Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Mathematical formula implementation

Reply
Thread Tools

Mathematical formula implementation

 
 
vhdl_newbie
Guest
Posts: n/a
 
      03-14-2013
Hello,
I am a beginner with learn VHDL and I need to implement a mathematical formula for a job interview.
I have one day to solve this problem so if there is any good samaritan that could help me with this problem, I would really appreciate it.

solve this formula for Y

Y=(P^2+K*P)/16

with

P = [0:63]
K = [0:4]
Y = [0:512]

Have a nice day !
 
Reply With Quote
 
 
 
 
vhdl_newbie
Guest
Posts: n/a
 
      03-14-2013
*I am a beginner with VHDL (sorry)

 
Reply With Quote
 
 
 
 
Fredxx
Guest
Posts: n/a
 
      03-14-2013
On 14/03/2013 22:23, vhdl_newbie wrote:
> Hello, I am a beginner with learn VHDL and I need to implement a
> mathematical formula for a job interview. I have one day to solve
> this problem so if there is any good samaritan that could help me
> with this problem, I would really appreciate it.
>
> solve this formula for Y
>
> Y=(P^2+K*P)/16
>
> with
>
> P = [0:63] K = [0:4] Y = [0:512]
>
> Have a nice day !
>


That looks like 4 variables and a single equation linking them together.

Have a great interview.
 
Reply With Quote
 
vhdl_newbie
Guest
Posts: n/a
 
      03-15-2013
Le jeudi 14 mars 2013 19:51:46 UTC-4, Fredxx a écrit*:
> On 14/03/2013 22:23, vhdl_newbie wrote:
>
> > Hello, I am a beginner with learn VHDL and I need to implement a

>
> > mathematical formula for a job interview. I have one day to solve

>
> > this problem so if there is any good samaritan that could help me

>
> > with this problem, I would really appreciate it.

>
> >

>
> > solve this formula for Y

>
> >

>
> > Y=(P^2+K*P)/16

>
> >

>
> > with

>
> >

>
> > P = [0:63] K = [0:4] Y = [0:512]

>
> >

>
> > Have a nice day !

>
> >

>
>
>
> That looks like 4 variables and a single equation linking them together.
>
>
>
> Have a great interview.


Thank you for your interest, the problem may be unclear but that is the wayit was written.
I think they want me to design an architecture with 9 bits output (Y), 2 bits (K) input and 5 bits input (P)
Do you have any idea of the functions I could use for product, division andeponentiation ?
(I am new to VHDL)
 
Reply With Quote
 
rickman
Guest
Posts: n/a
 
      03-15-2013
On 3/14/2013 6:23 PM, vhdl_newbie wrote:
> Hello,
> I am a beginner with learn VHDL and I need to implement a mathematical formula for a job interview.
> I have one day to solve this problem so if there is any good samaritan that could help me with this problem, I would really appreciate it.
>
> solve this formula for Y
>
> Y=(P^2+K*P)/16
>
> with
>
> P = [0:63]
> K = [0:4]
> Y = [0:512]
>
> Have a nice day !


If this were a real requirement, I would say there was something wrong
with it. It could be coded, but it would be hard to actually build. If
P is a 64 bit integer, it has a range of 0 to 2^64-1. As an exponent of
K, the result would have 2^64+4 bits. I don't know how to represent
that in a way that VHDL would understand. Heck, my calculator threw up
when I tried to calculate it.

Are you sure this is the right question? I can't see any value in
asking a job candidate such a question.

WAIT! The notation is wonkey! You mean the variables have his range,
not that many bits, right? That's different. But it still doesn't fit.
You can't shove the result into the range for Y.

Maybe that's what they want you to tell them?

--

Rick
 
Reply With Quote
 
Paul Uiterlinden
Guest
Posts: n/a
 
      03-15-2013
vhdl_newbie wrote:

> Hello,
> I am a beginner with learn VHDL and I need to implement a mathematical
> formula for a job interview. I have one day to solve this problem so if
> there is any good samaritan that could help me with this problem, I would
> really appreciate it.
>
> solve this formula for Y
>
> Y=(P^2+K*P)/16
>
> with
>
> P = [0:63]
> K = [0:4]
> Y = [0:512]


Assuming [0] are ranges,

FUNCTION y
(
p: natural range 0 TO 63;
k: natural range 0 TO 4
) RETURN natural IS
VARIABLE result: natural;
BEGIN
result := (p**2 + k*p)/16;
IF result > 512 THEN
result := 512;
END IF;
RETURN result;
END FUNCTION y;

Is this synthesizable? No idea, probably not, but it was not a requirement.

> Have a nice day !


And you!

--
Paul Uiterlinden
 
Reply With Quote
 
Fredxx
Guest
Posts: n/a
 
      03-15-2013
On 15/03/2013 13:11, Paul Uiterlinden wrote:
> vhdl_newbie wrote:
>
>> Hello,
>> I am a beginner with learn VHDL and I need to implement a mathematical
>> formula for a job interview. I have one day to solve this problem so if
>> there is any good samaritan that could help me with this problem, I would
>> really appreciate it.
>>
>> solve this formula for Y
>>
>> Y=(P^2+K*P)/16
>>
>> with
>>
>> P = [0:63]
>> K = [0:4]
>> Y = [0:512]

>
> Assuming [0] are ranges,
>
> FUNCTION y
> (
> p: natural range 0 TO 63;
> k: natural range 0 TO 4
> ) RETURN natural IS
> VARIABLE result: natural;
> BEGIN
> result := (p**2 + k*p)/16;
> IF result > 512 THEN
> result := 512;
> END IF;
> RETURN result;
> END FUNCTION y;
>
> Is this synthesizable? No idea, probably not, but it was not a requirement.
>
>> Have a nice day !

>
> And you!
>


I would have treated P, K and Y as 64, 5 and 513 element arrays
respectively?
 
Reply With Quote
 
Rob Gaddi
Guest
Posts: n/a
 
      03-15-2013
On Thu, 14 Mar 2013 22:13:53 -0400
rickman <(E-Mail Removed)> wrote:

> On 3/14/2013 6:23 PM, vhdl_newbie wrote:
> > Hello,
> > I am a beginner with learn VHDL and I need to implement a mathematical formula for a job interview.
> > I have one day to solve this problem so if there is any good samaritan that could help me with this problem, I would really appreciate it.
> >
> > solve this formula for Y
> >
> > Y=(P^2+K*P)/16
> >
> > with
> >
> > P = [0:63]
> > K = [0:4]
> > Y = [0:512]
> >
> > Have a nice day !

>
> If this were a real requirement, I would say there was something wrong
> with it. It could be coded, but it would be hard to actually build. If
> P is a 64 bit integer, it has a range of 0 to 2^64-1. As an exponent of
> K, the result would have 2^64+4 bits. I don't know how to represent
> that in a way that VHDL would understand. Heck, my calculator threw up
> when I tried to calculate it.
>
> Are you sure this is the right question? I can't see any value in
> asking a job candidate such a question.
>
> WAIT! The notation is wonkey! You mean the variables have his range,
> not that many bits, right? That's different. But it still doesn't fit.
> You can't shove the result into the range for Y.
>
> Maybe that's what they want you to tell them?
>


I think you're misreading. That's (P^P+K*P)/16, or P(P+K)/16

> --
>
> Rick



--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
 
Reply With Quote
 
rickman
Guest
Posts: n/a
 
      03-15-2013
On 3/15/2013 6:25 PM, Rob Gaddi wrote:
> On Thu, 14 Mar 2013 22:13:53 -0400
> rickman<(E-Mail Removed)> wrote:
>
>> On 3/14/2013 6:23 PM, vhdl_newbie wrote:
>>> Hello,
>>> I am a beginner with learn VHDL and I need to implement a mathematical formula for a job interview.
>>> I have one day to solve this problem so if there is any good samaritan that could help me with this problem, I would really appreciate it.
>>>
>>> solve this formula for Y
>>>
>>> Y=(P^2+K*P)/16
>>>
>>> with
>>>
>>> P = [0:63]
>>> K = [0:4]
>>> Y = [0:512]
>>>
>>> Have a nice day !

>>
>> If this were a real requirement, I would say there was something wrong
>> with it. It could be coded, but it would be hard to actually build. If
>> P is a 64 bit integer, it has a range of 0 to 2^64-1. As an exponent of
>> K, the result would have 2^64+4 bits. I don't know how to represent
>> that in a way that VHDL would understand. Heck, my calculator threw up
>> when I tried to calculate it.
>>
>> Are you sure this is the right question? I can't see any value in
>> asking a job candidate such a question.
>>
>> WAIT! The notation is wonkey! You mean the variables have his range,
>> not that many bits, right? That's different. But it still doesn't fit.
>> You can't shove the result into the range for Y.
>>
>> Maybe that's what they want you to tell them?
>>

>
> I think you're misreading. That's (P^P+K*P)/16, or P(P+K)/16


Yes, you are right. I misread the problem. Wouldn't be the first time
and won't be the last...

But the problem remains. If those are ranges, the general result won't
fit in the variable Y.

--

Rick
 
Reply With Quote
 
chrisabele
Guest
Posts: n/a
 
      03-16-2013
On 3/15/2013 6:29 PM, rickman wrote:
> On 3/15/2013 6:25 PM, Rob Gaddi wrote:
>> On Thu, 14 Mar 2013 22:13:53 -0400
>> rickman<(E-Mail Removed)> wrote:
>>
>>> On 3/14/2013 6:23 PM, vhdl_newbie wrote:
>>>> Hello,
>>>> I am a beginner with learn VHDL and I need to implement a
>>>> mathematical formula for a job interview.
>>>> I have one day to solve this problem so if there is any good
>>>> samaritan that could help me with this problem, I would really
>>>> appreciate it.
>>>>
>>>> solve this formula for Y
>>>>
>>>> Y=(P^2+K*P)/16
>>>>
>>>> with
>>>>
>>>> P = [0:63]
>>>> K = [0:4]
>>>> Y = [0:512]
>>>>
>>>> Have a nice day !
>>>
>>> If this were a real requirement, I would say there was something wrong
>>> with it. It could be coded, but it would be hard to actually build. If
>>> P is a 64 bit integer, it has a range of 0 to 2^64-1. As an exponent of
>>> K, the result would have 2^64+4 bits. I don't know how to represent
>>> that in a way that VHDL would understand. Heck, my calculator threw up
>>> when I tried to calculate it.
>>>
>>> Are you sure this is the right question? I can't see any value in
>>> asking a job candidate such a question.
>>>
>>> WAIT! The notation is wonkey! You mean the variables have his range,
>>> not that many bits, right? That's different. But it still doesn't fit.
>>> You can't shove the result into the range for Y.
>>>
>>> Maybe that's what they want you to tell them?
>>>

>>
>> I think you're misreading. That's (P^P+K*P)/16, or P(P+K)/16

>
> Yes, you are right. I misread the problem. Wouldn't be the first time
> and won't be the last...
>
> But the problem remains. If those are ranges, the general result won't
> fit in the variable Y.
>


I think Rob's rewriting is really helpful (aside from his forgetting to
change the ^ to a *). And if we assume that the values in [] are value
ranges rather than bit index ranges then the maximum Y value would be
63*(63+4)/16 = 264 which certainly is within the range [0:512]. Of
course I've assumed that Y must be an integer and truncated (actually
rounded) the result, plus the intermediate result is certainly much
larger than 512. But given those assumptions the problem is not
unreasonable. So perhaps the code that Paul posted is the best answer.

Perhaps the point of the interview question was to see if the candidate
would raise exactly the issues that have been discussed this thread...

Chris
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
jni to optimize a java application using native mathematical libraries dimitri.ognibene@gmail.com Java 16 04-06-2006 10:01 AM
mathematical String Evaluation kris Palmby ASP .Net 2 01-24-2006 02:05 PM
Rowfilters Mathematical Representation thecameleon06@hotmail.com ASP .Net 0 11-14-2005 08:52 AM
Mathematical formula used in dynamically rendered DataGrid Louis-Vincent Guay ASP .Net Datagrid Control 1 05-25-2004 09:02 PM
Mathematical Operations in VHDL MtnSurf8 VHDL 1 04-25-2004 06:07 AM



Advertisments