Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Algebra

Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
12-09-2009 04:23
Hi.

When working with Algeberic formulas.

Is there a way to make it understand the following(long ways, short hand)

integer x=4;
integer new = 3 * (2*x - 5);
integer shortHand = 3(2x - 5); // Cannot understand this.

llSay(0, (string)new);

ShortHand is not being understood, but is there a way to make it understand a formula like this?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-09-2009 07:01
whats wrong with what you had before the bad line?

new = 3 * (2 * x - 5);
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
12-09-2009 07:04
Nothing but their both correct, so shouldn't there be a way to make the shorter forumla work?
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
12-09-2009 07:23
Neither LSL, nor most other programming languages, are designed to make the sort of guesses and assumptions that humans need to make when interpreting shorthand algebraic notation, and this is a good thing. To make it work in LSL you need to make the multiplications explicit, and you do this using the asterisk multiplication operator.

It would be possible to write a parser that took the shorthand in the form of a string and figured out what was supposed to happen and then did it, and that would make a nice homework project for someone.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-09-2009 08:10
From: Pete Olihenge
Neither LSL, nor most other programming languages, are designed to make the sort of guesses and assumptions that humans need to make when interpreting shorthand algebraic notation, and this is a good thing. To make it work in LSL you need to make the multiplications explicit, and you do this using the asterisk multiplication operator.

It would be possible to write a parser that took the shorthand in the form of a string and figured out what was supposed to happen and then did it, and that would make a nice homework project for someone.

heh I have that parser built... it's not a simple bit of scripting, but does include the basic 5 and parenthesis, for ~200 lines of code (maybe only ~150 if I made it a function)

but more to the point, there are two basic reasons that math is not parsed that way in most programming languages....

one being that parenthesis have a different more variable interpretation in programming (namely as something which a function can be applied to) which requires specifying the operation to perform (whether it be math or a function cal, or storage)

the second being that variables are first and foremost, containers,to which the above also applies.

computers are very literal and expect explicit instructions on what to do with what, especially since, in normal context, multiple possible actions can occur. disallowing shorthand also prevents context assumptions from being misinterpreted and using the wrong operation when another was intended, preventing subtle errors in logic.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
12-09-2009 09:13
As a quick aside, something like this would likely benefit from recursion; how well does LSL handle that?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-09-2009 13:35
From: Pete Olihenge
As a quick aside, something like this would likely benefit from recursion; how well does LSL handle that?

not well at all (it can be done, but I really Really, REALLY don't recommend it). of course you know that any recursive function can be rewritten as iterative (or vice versa for that matter).

the biggest problem being that variables are passed by value, and not by reference, the second being memory limits.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
12-09-2009 13:52
Then I shall try to avoid having ideas that involve recursion. I had a (literal) nightmare the other night involving scripts - I hope that doesn't become recursive.
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
12-24-2009 04:06
From: Void Singer
heh I have that parser built... it's not a simple bit of scripting, but does include the basic 5 and parenthesis, for ~200 lines of code (maybe only ~150 if I made it a function)
Sorry to ressurect this thread, but just now I had a moment where an in-world algebraic chat calculator would've been handy...

I suppose I should really look up whatever superceeded the old Windows Power Toy calculator...

But then again, I do like to keep things in-world when possible...

Void, I don't suppose you'd consider publishing that parser code?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-24-2009 05:12
From: Pete Olihenge
Void, I don't suppose you'd consider publishing that parser code?

I had thought about it... although currently it's being used in a for profit product. if I finish the version that supports the basic 6 trig functions plus abs and ln, I will definitely. (and I just checked, the function version is 99 lines of actual code double that w/ whitespace and comments).

I will however drop a free copy of the product on you to use, since you were the first to ask.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
12-24-2009 10:09
Many thanks, Void. A user definable function would be nice too :)