Skip to content

Add Bits.sub - jonathanrlouie#115

Closed
MaisaMilena wants to merge 1 commit into
masterfrom
bits_sub
Closed

Add Bits.sub - jonathanrlouie#115
MaisaMilena wants to merge 1 commit into
masterfrom
bits_sub

Conversation

@MaisaMilena

Copy link
Copy Markdown
Contributor

Update to the new syntax from Moonad#16

@VictorTaelin

Copy link
Copy Markdown
Member

This is nice, but a bit too long. We should just use the same algorithm as Bits.inc?

@jonathanrlouie

Copy link
Copy Markdown
Contributor

@MaiaVictor I'm not seeing how Bits.sub can use the same algorithm as Bits.inc. Can you elaborate a bit on how that would work?

@jonathanrlouie

Copy link
Copy Markdown
Contributor

Just had a realization. Would this be better?

Bits.sub(a: Bits, b: Bits): Bits
  Bits.reverse(Bits.sub.go(a, b, Bits.e))

Bits.sub.go(a: Bits, b: Bits, bits: Bits): Bits
  case b {
    e: case a {
      e: bits,
      o: Bits.sub.go(a.pred, b, Bits.o(bits)),
      i: Bits.sub.go(a.pred, b, Bits.i(bits))
    },
    o: case a {
      e: Bits.sub.go(a, b.pred, Bits.o(bits)),
      o: Bits.sub.go(a.pred, b.pred, Bits.o(bits)),
      i: Bits.sub.go(a.pred, b.pred, Bits.i(bits))
    },
    i: case a {
      e: Bits.e,
      o: Bits.sub.go(a.pred, Bits.inc(b.pred), Bits.i(bits)),
      i: Bits.sub.go(a.pred, b.pred, Bits.o(bits))
    }
  }

I also realized that I can't update this branch, since I don't have permissions. Do I need to create a separate PR?

@VictorTaelin

Copy link
Copy Markdown
Member

I meant in the sense of creating a Bits.dec algorithm and then applying it n times. But in retrospect, that will be slow in non-optimal evaluators. Your code is clean and nice. Seems like it is conflicting though. @MaisaMilena can you check if it type-checks and merge?

Thanks for the contrib! (:

@MaisaMilena

Copy link
Copy Markdown
Contributor Author

@jonathanrlouie can you open a new PR with your solution? As you can't update this PR I will close it.

@jonathanrlouie jonathanrlouie mentioned this pull request Dec 11, 2020
@MaisaMilena MaisaMilena deleted the bits_sub branch December 15, 2020 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants