8,235 karma · joined September 15, 2007
julesjacobs.com
If you do sanity checks in Rust then you should panic instead of returning options. However, in this case you cannot do the sanity checks, because the contract of the function is that it will only call the predicate strictly between l and r (i.e., only on indices returned by mid). Further, given the initial sanity checks, the sanity checks inside the loop body are redundant, as the loop invariant ensures that those checks never fail.
[1] https://julesjacobs.com/notes/binarysearch/binarysearch.pdf [2] https://byorgey.wordpress.com/2023/01/01/competitive-program...
Here is a Rust implementation of the original:
pub fn search<T: Mid, G>(predicate: G, mut l: T, mut r: T) -> (T, T)
where G: Fn(&T) -> bool
{
loop {
match l.mid(&r) {
None => return (l, r),
Some(m) => {
if predicate(&m) { r = m }
else { l = m }
}
}
}
}
Or, traitless: pub fn search<T, H, G>(mid: H, predicate: G, mut l: T, mut r: T) -> (T, T)
where H: Fn(&T,&T) -> Option<T>, G: Fn(&T) -> bool
{
loop {
match mid(&l, &r) {
None => return (l, r),
Some(m) => {
if predicate(&m) { r = m }
else { l = m }
}
}
}
}That is the opposite of criticism. It all translates to "GPT-(n+1) is going to be super awesome".
It's easy to get in trouble with an interconnected object graph: you mess up and hold onto a pointer that you shouldn't be holding onto, which results in a leak.
*((int*)rand()) = 42Note that I am not talking about UB like signed integer overflow. Removing that would slow down programs by a couple of percent. The important type of UB is pointer provenance. This ensures that e.g., writing to a random memory address is UB.
I would not want to be in such a relationship, to be honest. Just learn to accept each other's small flaws and try to be kind. Little things only build up if you let them. Verbalising everything and putting negativity into focus is actually one of those ways that scar tissue can build up. The best way for it to not build up is to let the little things go.
- Income tax: 49.5% (36.93% on income under €73k)
- Inheritance tax: 40% (30% for inheritance under €138k)
- VAT: 21%
Thus, poor people pay 65% tax and rich 76% in such a scenario.
I'm convinced that doesn't require a breakthrough in the architecture or scale of LLMs, though. GPT-4 seems plenty smart enough to be able to learn that, if hooked up to a proof assistant like Lean or Coq with the right fine tuning iteration loop.