Author Topic: Sanger  (Read 12325 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Sanger
« Reply #15 on: November 25, 2007, 12:29:25 PM »
Very nice.  I think the ternary operator is a little non intuitive, but I come from a C background, so maybe it's based on something in Perl?  I don't know how hard it would be, but something like:

if A && B || C then ... else ...

would mirror the DNA's structure and be more intuitive.

Also, I'm unfamiliar with Perl's && || operators.  Others probably are too.  Could you explain what they do?
« Last Edit: November 25, 2007, 12:31:10 PM by Numsgil »

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Sanger
« Reply #16 on: November 25, 2007, 02:04:39 PM »
Well yes what do they, and will this be backward compatible. Dna->sanger
« Last Edit: November 25, 2007, 02:19:33 PM by Peter »
Oh my god, who the hell cares.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #17 on: November 25, 2007, 02:50:44 PM »
Quote from: Numsgil
Very nice.  I think the ternary operator is a little non intuitive, but I come from a C background, so maybe it's based on something in Perl?  I don't know how hard it would be, but something like:

if A && B || C then ... else ...

would mirror the DNA's structure and be more intuitive.

Also, I'm unfamiliar with Perl's && || operators.  Others probably are too.  Could you explain what they do?
I'm going to introduce if later with the following syntax:
Code: [Select]
if ( ... ) {
    ...
}
else {
    ...
}
But there are some difficulties in implementation:
  • Assigning to a variable in then and else which is used in the condition. This includes assigning to an expression, since expression may evaluate to an address of the variable used in the condition. Evaluation of the variable's address at compile time may be a complex task. Sometimes expression cannot be evaluated at the compile time at all (e. g. rnd(1000) ).
  • Using rnd(...) in the condition.
Perhaps I'll just forbid
  • using rnd() in condition expression
  • using variables modified inside then and else clauses in condition expression
  • assigning to expressions inside then and else
Naturally if is already implemented, all I need to implement those checks, that is quite a bore.

Ternary conditional assignment operator is not met in Perl, though you can say in Perl:
Code: [Select]
$a = 1 if $b == 0;Perhaps it is prettier, isn't it? I still can change to this syntax without much effort. What do you think?

&& and || work in Perl and Sanger as follows:
  • a && b equals a if a is false (== 0 in Sanger's case), b otherwise (no matter if b is true or false)
  • a || b equals a if a is true (!= 0 in Sanger's case), b otherwise (no matter if b is true or false)
Since it is so, you may do conditional assignment an extra way:
Code: [Select]
*.nrg > 20000 && .repro = 10;which is basically the same as
Code: [Select]
.repro ?? *.nrg > 20000 = 10;But ternary conditional operator has an additional possibility to use this in condition. It refers to the value of the expression you assign. It is implemented with dup assembly operator.

Quote from: Peter
Well yes what do they, and will this be backward compatible. Dna->sanger
Though I don't understand what you mean by 'backward compatible', I can assure you it won't make trouble. Sanger tracks boolean and integer contexts and modifies integer values met in boolean context accordingly (with sgn abs).

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Sanger
« Reply #18 on: November 25, 2007, 02:58:01 PM »
Quote from: Gobo
Quote from: Peter
Well yes what do they, and will this be backward compatible. Dna->sanger
Though I don't understand what you mean by 'backward compatible', I can assure you it won't make trouble. Sanger tracks boolean and integer contexts and modifies integer values met in boolean context accordingly (with sgn abs).
Ok, what I mean.

With sanger you do.
sangercode--->DB-dna
Can you also do
DB-dna--->sangercode

So having normal dna and with it making sanger.
Edit: I know at this very moment it isn't possible, but is it going to be.
« Last Edit: November 25, 2007, 02:59:41 PM by Peter »
Oh my god, who the hell cares.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #19 on: November 25, 2007, 03:13:46 PM »
Quote from: Peter
With sanger you do.
sangercode--->DB-dna
Can you also do
DB-dna--->sangercode

So having normal dna and with it making sanger.
Edit: I know at this very moment it isn't possible, but is it going to be.
"Decompiling" is just another task. You cannot just take any DNA code and transform it into Sanger, since DNA code produced with Sanger is just a subset of all possible DNA code. I'm planning to write a tool, which would deobfuscate DNA code a little bit. But at the moment, I cannot advance because I don't understand how cond-start-else work exactly. I need to experiment with those.
« Last Edit: November 25, 2007, 03:29:43 PM by Gobo »

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Sanger
« Reply #20 on: November 25, 2007, 03:40:38 PM »
Quote from: Gobo
"Decompiling" is just another task. You cannot just take any DNA code and transform it into Sanger, since DNA code produced with Sanger is just a subset of all possible DNA code. I'm planning to write a tool, which would deobfuscate DNA code a little bit. But at the moment, I cannot advance because I don't understand how cond-start-else work exactly. I need to experiment with those.
Yes, decompiling is the word.   I thought that you made with your program normal animal minimalis dna, but you make SGinised animal minimalis dna.
And, yes there are different kinds of programming. Could be nice to see animal minimalis being changed ito his SGinised version this way.

But further you say this is pre-alpha, is it already possible to make all kinds of bots or was this just an example. I could maybe try and see, but I have a little difficulty to understand it all.

I don't know much different programing-langues so that could also be me. If there is a manuel maybe I am taking a look. Undocumated it will probably too hard.
Oh my god, who the hell cares.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #21 on: November 25, 2007, 04:07:35 PM »
Classic animal minimalis with conditional genes will look like the following:
Code: [Select]
friendly() -> *.refeye == *.myeye;

/* Food Finder */
when ( *.eye5 > 0 && !friendly() ) {
    .dx = *.refveldx;
    .up = *.refvelup + 30;
}

/* Eat Food */
when ( *.eye5 > 50 && !friendly() ) {
    .shoot = -1;
    .up = *.refvelup;
}

/* Avoiding Family */
when ( *.eye5 == 0 || friendly() ) {
    .aimdx = rnd(314);
}

/* Reproduce */
when ( *.nrg > 20000 ) {
    .repro = 10;
}
Here I changed familiar if-else syntax to when-otherwise in order to explicitly differentiate between if-else that will encounter inside genes due to limitations in if-else constructs described above (when-otherwise construct won't have these limitations naturally). But if community decides it is not essential, I may use the same syntax for both (what do you say?).

It is called pre-alpha because syntax is subject to change (e. g. I'm now inclined to change ... ?? ... = ... syntax in favor of ... = ... if ...), documentation is not yet here, and there may be some several bugs, since it was not thoroughly tested. Also I'd like to introduce if-else construct in alpha. Though it is quite functional. You can write in anything you want, not just Animal Minimalis, for sure

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Sanger
« Reply #22 on: November 25, 2007, 06:11:52 PM »
A DNA deobfuscater (sp? ) would be very helpful, too.  Though considering how insane DNA can get it's not an easy task.  The simplest would be to backtrack from all the store, inc, or dec operators and remove and "junk" dna that doesn't effect the final result.  Some sort of DNA stripper.

I don't mind the when...otherwise thing.  Makes the language have character

The ternary operator in C (which is what I'm used to) operates like this:

a ? b : c, which is the same as:

if a then b else c.  So if your ternary operator is significantly different from that form, there's some unlearning that needs to be done by people like me.  And Perl's && and || syntax seem a little alien to me, though you explained it very well.  I might need to do some quick research.

With the new changes to conditions, it actually simplifies a lot of the DNA.  You can totally get rid of cond blocks and just have a long start statement.  I might write up a new version of animal minimalis in another thread as a demonstration.  I think it should make some of what you're doing easier, too.
« Last Edit: November 25, 2007, 06:15:17 PM by Numsgil »

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Sanger
« Reply #23 on: November 25, 2007, 09:44:32 PM »
I second the call that an evolved DNA deobfuscator would be very useful.  Building a complete one is harder than it sounds though.  I been thinking of doing it in the simulator since by doing so, I could leverage the actual DNA execution logic which of course knows which things to ignore and which not to but the problem is that it doesn't know that at the moment the instruction pointer is on the base pair.   It only knows down the road, when the boolean stack is cleared by a cond for example etc. as to whether boolena values pushed on the boolean stack got used.  It can't make a real time decision as to whether removing a BP will impact the logic.    

A few things are easy.  Removing all non-coding DNA for example.  But doing a complete job is a non-trivial task.

Oh, and Sanger looks cool.  When I get two minutes to rub together I'll dive in.
Many beers....

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #24 on: November 30, 2007, 05:58:16 PM »
Sanger 2.0 (alpha) is released!
http://www.ersatz.org/sanger-2.0.zip - source
http://www.ersatz.org/sanger.html - online

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Sanger
« Reply #25 on: November 30, 2007, 06:05:30 PM »
Does it allow nested conditions?  Animal Minimalis's second gene is collapsable in to the first if you nest it.  I tried doing it myself, and it didn't yell at me and seemed to compile, but I'm too lazy to double check it to see if it did it right.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Sanger
« Reply #26 on: November 30, 2007, 06:15:41 PM »
Also, you don't need to start the DNA with a cond.  You can just have a start statement, because an empty bool stack is assumed to be true, so a start statement will run without a cond.  Second, you don't need a stop statement.  Once the end of the DNA is reached, a stop and end command are assumed.

Also, it would be nice if the compiled DNA result was formatted a little better.  It gave me this for my Animal Minimals tweak:

Code: [Select]
cond
start
*.eye5 0 > *.refeye *.myeye != and *.refveldx .dx store
*.refvelup 30 add .up store
*.eye5 50 > -1 .shoot store
*.refvelup .up store true or and true or and
*.eye5 0 = *.refeye *.myeye = or 314 rnd .aimdx store true or and
*.nrg 20000 > 10 .repro store true or and
stop

Where something like this would look better:

Code: [Select]
start
*.eye5 0 >
*.refeye *.myeye != and
*.refveldx .dx store
*.refvelup 30 add .up store

*.eye5 50 >
-1 .shoot store
*.refvelup .up store

true or and true or and
*.eye5 0 =
*.refeye *.myeye = or
314 rnd .aimdx store

true or and
*.nrg 20000 >
10 .repro store

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #27 on: November 30, 2007, 06:26:18 PM »
Yes, surely it's collapsable. You can do arbitrary deep nested ifs. I just wanted to save the whole logic of Animal Minimalis to have a better analogy.
Code: [Select]
friendly() -> *.refeye == *.myeye;

always {
    /* Food Finder + Eat Food + Avoiding Family */
    if ( *.eye5 > 0 && !friendly() ) {
        .dx = *.refveldx;
        if ( *.eye5 > 50 ) {
            .shoot = -1;
            .up = *.refvelup;
        }
        else {
            .up = *.refvelup + 30;
        }
    }
    else .aimdx = rnd(314);
    
    /* Reproduce */
    if ( *.nrg > 20000 ) .repro = 10;
}
Formatting is in the queue. It's not of the first priority, I hope you agree.

Perhaps I will remove cond from definition of always gene. But stop is better to stay, imho, because there may be more than one gene, and it's not a great deal to save a single command in the special case of the last gene.
« Last Edit: November 30, 2007, 06:56:07 PM by Gobo »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Sanger
« Reply #28 on: November 30, 2007, 06:32:10 PM »
Quote from: Gobo
Yes, surely it's collapsable. You can do arbitrary deep nested ifs.

Will it handle changes to the condition or integer stack?  That is, if I do:
Code: [Select]
if (false) {
10
} else {
20 store
}

Will it store 10 to 20 or not?  It's not supposed to, though this is a rather pathological example.

Quote
Perhaps I will remove cond from definition of always gene. But stop is better to stay, imho, because there may be more than one gene, and it's not a great deal to save a single command in the special case of the last gene.

True.
« Last Edit: November 30, 2007, 06:32:35 PM by Numsgil »

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Sanger
« Reply #29 on: November 30, 2007, 06:40:24 PM »
You cannot operate stacks directly with Sanger 2.0 (at least, at the moment). You must store a value into the memory. Otherwise there would be much confusion, because the integer stack is used for expressions evaluation.

Though 'if (false)' shall work right (it doesn't, because I forgot to define true and false   )
« Last Edit: November 30, 2007, 06:42:32 PM by Gobo »