Author Topic: Auto Optimization Program  (Read 48718 times)

0 Members and 1 Guest are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Auto Optimization Program
« on: September 01, 2010, 02:54:09 pm »
So i was inspired by SourceCoders' broken Basic Optimizer function, and i thought about making one on the calculator, so you could optimize your Basic Programs without having to transfer them to the computer for any utility.  I quickly wrote up some code in Axe, and the optimizations have started :)  Currently it has support for:

Ending Parenthasis
Ending Quotes
Devlar
Powers of 10
Squared and Cubed optimizations

And there is plans and psedocode for

Implied multiplication
=0 into Not(
Negative/Positive cancellation

any other ideas of simple find and replace optimizations that i could put into the optimizer?  Obviously i cant do some of the complicated stuff, but there are some good simple replacements that can make a big difference.  And note that it ignores Strings completely :) Strings Should not be changed ^^.  And there also might be an option on whether to erase empty lines or not.  Some people like to keep them for readability during development, and then maybe want to take them out later.
« Last Edit: September 02, 2010, 01:45:58 am by Builderboy »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Auto Optimization Program
« Reply #1 on: September 01, 2010, 02:56:07 pm »
Ooh, good idea.

Another one: .01 or /100 into sub(.

EDIT: And if it's possible, a logic simplifier.

EDIT2: 403 Forbidden
« Last Edit: September 01, 2010, 03:20:45 pm by Deep Thought »




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Auto Optimization Program
« Reply #2 on: September 01, 2010, 03:00:04 pm »
what do you mean sub(.? And what do you mean by a logic simplifier? ;D

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Auto Optimization Program
« Reply #3 on: September 01, 2010, 03:03:05 pm »
Oh, just sub(, as in like how sub(1 returns 0.01. The period was just for grammatical purposes ;D

And by a logic simplifier, I mean the kind that automatically turns A and B or not(A into A or B. They're not very hard to code. The hard part is getting them to recognize A and B in a statement.

EDIT: 404 Not Found
« Last Edit: September 01, 2010, 03:21:04 pm by Deep Thought »




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Auto Optimization Program
« Reply #4 on: September 01, 2010, 03:05:46 pm »
Wow i didnt know about that XD Sounds good :)

And i'll have to see if i can get the logic simplifier to work, it might be tricky but i think i *might* be able to get it working.  i will have to do some research

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Auto Optimization Program
« Reply #5 on: September 01, 2010, 03:13:52 pm »
And i'll have to see if i can get the logic simplifier to work, it might be tricky but i think i *might* be able to get it working.  i will have to do some research

I think HarrierFalcon or Weregoose had a really good one somewhere. Can't find it now, but here's a copy I have (edited a bit):

Code: (TI-BASIC) [Select]
:ClrHome
:Input "LOGIC IN
 A & B: ",Str1
:DelVar C
:ClrHome
:Disp "    A","
  0 1","  +---",
" 0!","B !"," 1!

:For(A,0,1
:For(B,0,1
:C+not(expr(
Str1)))10^(2A+B→C

:Output(2B+4,2A+
4,not(not(expr(S
tr1
:End
:End
:Pause sub("0  
not(A or BB   B
or not(AA and no
t(Bnot(B  A or B
 1   A and B not
(A xor BB and no
t(Anot(A  A   A
or not(BA xor B
not(A and B",1+6
4fPart(Ans/16),4


EDIT: This one's a homescreen program that takes as input a logic statement in A and B, but it can probably be changed to do it in a program.

EDIT2: The program's also compressed by that idea of dividing a binary number as a decimal number by a hex humber (what's that called, anyway?), so it might be kinda hard to read, but basically, a sequence of TRUE and FALSE values is stored directly as a decimal number (such as 1011), then divided by 16 (or 64 in this case, since each entry in the string is 4 tokens long). The fractional part multiplied by 16 is always different, so the weird order's based on that.

EDIT3: Sorry if this is confusing. I'm really, really bad at explaining things.
« Last Edit: September 01, 2010, 03:18:23 pm by Deep Thought »




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Auto Optimization Program
« Reply #6 on: September 01, 2010, 05:59:16 pm »
Thats really cool!  Hmm it might be very tricky to implement tho, since it would have to do some pretty weird calculations to determine A and B, and if 1 expression is equivalent to another.  And it only works if there are 2 expressions present in the logic line.

For now i think im going to stick to simple find and replace, then go into more detailed optimizations.  Maybe things like reordering expressions so that expressions with more parenthesis are at the end of the line.  Like optimizing

Dim(L1)+1

to

1+Dim(L1

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Auto Optimization Program
« Reply #7 on: September 01, 2010, 06:23:25 pm »
Another good one would be to auto-expand calculations if they are factored (ex. 5(B+3)+A-(5+W)=5B+15+A-5-W=5B+A-W+10).

But this is a cool idea :) Will really help some people.

@Deep Thought
I've noticed lately that when you're posting code that there appears an empty code box and then the code itself below the box. Is there any reason for that or am I the only one experiencing it?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Auto Optimization Program
« Reply #8 on: September 01, 2010, 06:24:32 pm »
Another good one would be to auto-expand calculations if they are factored (ex. 5(B+3)+A-(5+W)=5B+15+A-5-W=5B+A-W+10).

But this is a cool idea :) Will really help some people.

@Deep Thought
I've noticed lately that when you're posting code that there appears an empty code box and then the code itself below the box. Is there any reason for that or am I the only one experiencing it?

Yeah, it's on purpose since I occasionally need to use something like 10^(, which wouldn't show up well in code tags.




Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Auto Optimization Program
« Reply #9 on: September 01, 2010, 06:26:34 pm »
Ah ok. The empty code box just looks weird so I thought it might have been some kind of error happening.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Auto Optimization Program
« Reply #10 on: September 01, 2010, 06:33:42 pm »
Another good one would be to auto-expand calculations if they are factored (ex. 5(B+3)+A-(5+W)=5B+15+A-5-W=5B+A-W+10).

Thats also a good idea, i will have to see if its doable.  Sometimes it wont actually result in less tokens tho, so i will have to remember that.  Also i would need to write a number to token converter, working with all these tokens is tough business :P

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Auto Optimization Program
« Reply #11 on: September 01, 2010, 06:36:23 pm »
It doesn't? I thought it always did, at least for me it always has. What's a situation where it doesn't?

Don't you already have one sorta since you were working on that on-calculator program editor?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Auto Optimization Program
« Reply #12 on: September 01, 2010, 06:36:29 pm »
Another good one would be to auto-expand calculations if they are factored (ex. 5(B+3)+A-(5+W)=5B+15+A-5-W=5B+A-W+10).

Thats also a good idea, i will have to see if its doable.  Sometimes it wont actually result in less tokens tho, so i will have to remember that.  Also i would need to write a number to token converter, working with all these tokens is tough business :P

For the num>token thing, I think you can first display it on the screen (with >Dec), then get the tokens from TextShadow (I think it's L5).




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Auto Optimization Program
« Reply #13 on: September 01, 2010, 06:42:32 pm »
Something like 99(99+A would distribute into 9801+99A which is 1 more token :( And thats a really clever idea with the Screen trick!  Im going to go put that in my subroutine :)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Auto Optimization Program
« Reply #14 on: September 01, 2010, 06:45:26 pm »
Yeah, auto-expansion might not be a good idea, since most factored expressions are shorter than their expanded forms :P

Something like 99(99+A would distribute into 9801+99A which is 1 more token :( And thats a really clever idea with the Screen trick!  Im going to go put that in my subroutine :)

Remember to change the screen immediately afterward, or else the user's gonna get confused by random numbers on the screen :D