In my program, I have something like;;

Code:

:Input "FIRST EQ:",Str0
:Input "SECND EQ:",Str1
:Str0->Y1
:Str1->Y2

Now my question; Is it legal to call something like this?

Code:

:((Y1(3))/(Y2(3)))->X

Basically, plug 3 into the first equation, then divide that answer by 3 plugged into the second equation.
p.s I know I probably have redundancies in those parenthesis :p
p.s.s Thanks in advance Smile
I'm sure it is. By the way, the graphing vars are a great technique to use in general that I ought to have used a lot more. They can serve as lambdas (first class functions). ...Anyway, I don't see any reason why it should not work. You could always test it.

On a side note for testing, if you don't have an emulator, I recommend downloading wabbitemu (just google it). It's great for testing on your computer if you don't have your calc on hand Smile

P.S. To answer the question you told me not to:

Code:
:Y1(3)/Y2(3->X
If Y1 = 3x, would Y1(3) basically be Y1 = 3*3? Or are you telling the calculator multiply that by three?
Yes, that would definitely work.
comicIDIOT wrote:
If Y1 = 3x, would Y1(3) basically be Y1 = 3*3? Or are you telling the calculator multiply that by three?

It would be Y1=3*3.
shkaboinka wrote:
They can serve as lambdas (first class functions).


While they are cool to use and do serve the purpose of simple functions, they aren't first class, since you cannot easily pass them around or call them in a non-strict or non-explicit manner in TI-BASIC. Plus, the meaning of a lambda is a non-explicit function, or rather, an anonymous one -- the definition isn't a "first class function entity", to pick on your diction there Wink
Isn't (Y1)/(Y2) the same thing as (Y1(3))/(Y2(3)) because the 3 cancels out?

I am not sure if I am understanding you? Is this what you mean joshie?

Also if you want to plug in "3" for the "X" in the string use can do this:


Code:

3→χ
expr(Str0)/expr(Str1)→χ
rohi89 wrote:
Isn't (Y1)/(Y2) the same thing as (Y1(3))/(Y2(3)) because the 3 cancels out?


No. Not giving an input to a function call will pretend that X is the input, and that would only work like "f x = x * 3" if he did "3→X" beforehand. It's not a matter of them canceling out, but rather a matter of how you are working with functions.
Thanks for all the posts guys,
Thanks shkaboinka for the code optimization!
And rohi89, I did not know that, thanks Smile
rohi89 wrote:
Isn't (Y1)/(Y2) the same thing as (Y1(3))/(Y2(3)) because the 3 cancels out?


As stated, this is not true, because you do not know WHAT those functions are doing with their inputs. For example, (a+X)/(b*X) is not the same as a/b.

Ashbad: Yeah, I guess I got lazy with the terminology Razz ... I say "first class" meaning they are proper variables. The fact that they cannot be passed is a limitation of all the variables in TI-BASIC. When I think of an anonymous instance of something ... my head has been thinking like an optimizing compiler which would treat an anonymous instance the same as a declared instance only used once. In either case, the instance would generally be created and then pointed to, and it's the pointer rather than the instance that is the variable anyway ... but I am getting off topic. The point is that you have "function variables", which is what they are called in the first place, but I never thought to think "function variables" in the context of programming for TI-BASIC until now, and I think it's pretty snazzy Smile
Because the Y1, Y2, ... Y0 tokens do not have a parenthesis, in most cases the following code:

Code:
:0->X:"4X"->Y1
:Y1(3)

Would be the same as Y1(0)*3. However, to my surprise, the parser actually notices the parentheses and treats them as proper arguments for X rather than implicit multiplication. So the long story short is yes, your code would work.
Thanks everyone Smile

Another quick question for this program. What would be the most effective way to display my list? The only ways I know of would be
1) Disp LLIST... and have the user scroll left and right to view the numbers
2) Something like,

Code:

:1->X:1->Y:1->L:1->B
:While B=/=0
:LLIST(L->B
:Output(Y,X,LLIST(L
:Y+1->Y
:L+1->L
:End

That second method would be my normal approach, but the list could have more than 7 elements, depending on the users inputs, which would run the others upscreen and out of view :\
I would think that the code as you presented it would be more like this:
Code:
:For(B,1,dim(LLIST
:Output(B,1,LLIST(L
:End
How about something like this?
Code:
:For(B,1,dim(LLIST
:Output(B,1,LLIST(L
:If B/8=int(B/8
:Pause
:End
The If conditional will only be true if B is a multiple of 8, so it will pause every 8 items.
Kerm, that B will increment beyond 8. I think you meant:
Output(8fpart(B/8),1,LLIST(B
shkaboinka wrote:
Kerm, that B will increment beyond 8. I think you meant:
Output(8fpart(B/8),1,LLIST(B
Yes, it will display the list, but it will pause every 8 items so that you don't miss anything.
Right. But when B is 9 (after the pause), your code is telling it to output it at row 9 (etc.) which does not exist. Also (and this is being really nit-picky of me) "If not(fpart(B/8" saves 3 bytes. But I also just realized that my suggestion puts it at row 0-7. Anyway, this should work:

Code:
:For(B,1,dim(LLIST
:Output(1+8fpart((B-1)/8,1,LLIST(B
:If not(fpart(B/8
:Pause
:End
Oh, I totally overlooked that; thanks for catching that. This is why I need to be sure to test my code. Wink
joshie: The example I last gave should work, but here is a version of it that is easier to understand (though it uses a bit more code). Also, I added more Outputs which just tell you which row you are looking at overall (you can remove those if you like):


Code:
:Delvar A
:For(B,1,dim(LLIST
:A+1→A
:Output(A,1,LLIST(B
:Output(A,11,"ROW
:Output(A,14,B
:If A=8
:Then
:Pause
:Delvar A
:End
:End
Not to be a pain, but you omitted the best part of using Delvar (although you probably did so for the sake of clarity):


Code:
:Delvar AFor(B,1,dim(LLIST
:A+1→A
:Output(A,1,LLIST(B
:Output(A,11,"ROW
:Output(A,14,B
:If A=8
:Then
:Pause
:Delvar AEnd
:End
...I've gotta say, TI-BASIC has some gross optimization tricks ... But I guess that's the magic of tokens (easy parsing). If I want, I could make a token-based editor for OPIA (separately), since the tokenizing and parsing and everything else will be accessible by other programs Smile
I will be sure to optimize my code, I continue to get better at Ti coding, thanks to all you guys Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement