Switch around ordering of question combining

This has the advantage that for some ModulusInformation object m and
some modulus,

```
a = m.split(modulus);
m.cast_down(x);
```

is equivalent to

```
m.cast_down(x*modulus);
a = m.split(modulus);
```

This means that when using a ModulusInformation object to answer
questions, we can answer the first question without needing to know how
many questions there are.
This commit is contained in:
Felix Bauckholt 2019-03-03 22:50:20 +01:00
parent 96da95dbba
commit e510f7cc5e
2 changed files with 6 additions and 6 deletions

View file

@ -73,5 +73,5 @@ On the first 20000 seeds, we have these average scores and win rates:
|---------|---------|---------|---------|---------|
| cheat | 24.8594 | 24.9785 | 24.9720 | 24.9557 |
| | 90.59 % | 98.17 % | 97.76 % | 96.42 % |
| info | 22.3249 | 24.7278 | 24.8919 | 24.8961 |
| | 09.81 % | 80.54 % | 91.67 % | 91.90 % |
| info | 22.3316 | 24.7246 | 24.8892 | 24.8969 |
| | 09.81 % | 80.38 % | 91.45 % | 91.94 % |

View file

@ -29,7 +29,7 @@ impl ModulusInformation {
}
pub fn combine(&mut self, other: Self) {
self.value = self.value * other.modulus + other.value;
self.value = self.value + self.modulus * other.value;
self.modulus = self.modulus * other.modulus;
}
@ -39,10 +39,10 @@ impl ModulusInformation {
let original_modulus = self.modulus;
let original_value = self.value;
self.modulus = self.modulus / modulus;
let value = self.value / self.modulus;
self.value = self.value - value * self.modulus;
let value = self.value % modulus;
self.value = self.value / modulus;
assert!(original_modulus == modulus * self.modulus);
assert!(original_value == value * self.modulus + self.value);
assert!(original_value == value + modulus * self.value);
Self::new(modulus, value)
}