robby
2017-3-17 11:59:33

@leafac : the rules for the single step overlap with the rule that breaks out the and.


robby
2017-3-17 12:00:49

And then the rules don’t work because there are no contexts.


mflatt
2017-3-17 14:42:58

I’m getting build errors during making for <pkgs>/racket-benchmarks/tests/racket/benchmarks/shootout/typed – and it looks like the Utah snapshot build failed for that reason, too. Known problem?


leafac
2017-3-17 14:51:04

@robby:

> the rules for the single step overlap with the rule that breaks out the and.

You mean that and and concat are resolved by the same reduction relation? In fact, if I were to write that, I would define a concat meta-function. Because the meta-function execution would not take one node in the reduction graph.

> And then the rules don’t work because there are no contexts.

What do you mean by “contexts?” I still don’t see where it would break. Can you please explain some more? Or at least point me what I need to learn?

Thank you so much for your time :slightly_smiling_face:


jaerme
2017-3-17 15:40:37

@jaerme has joined the channel


robby
2017-3-17 15:40:43

@leafac mostly what I’m saying is that you should give a try. Redex will be your guide! Plus, there are more interesting things to discover if you want to work up to actually making add work.


robby
2017-3-17 15:40:53

That said, let me try to at least explain what I meant with those specific comments.


robby
2017-3-17 15:41:37

(give me a sec to write some code)


robby
2017-3-17 15:43:37

With this definition (the one I was hinting at above):


robby
2017-3-17 15:43:40
#lang racket
(require redex)
(define-language L
  (e ::=
     (b ...)
     (and e e)
     (concat e ...))
  (b ::= 0 1))

(define red
  (reduction-relation
   L
   (--> (and (b_1 ...) (b_2 ...))
        (concat (and (b_1) (b_2)) ...))
   (--> (concat (b ...) ...)
        (b ... ...))
   (--> (and (0) (b)) (0))
   (--> (and (b) (0)) (0))
   (--> (and (1) (1)) (1))))

(traces
 red
 (term (and (1 0 1 0) (0 0 1 1))))

robby
2017-3-17 15:44:06

you get only one step; the last three rules don’t fire because they don’t have a context around them.


robby
2017-3-17 15:45:44

Now we can fix that by introducing and using E:


robby
2017-3-17 15:45:51
#lang racket
(require redex)
(define-language L
  (e ::=
     (b ...)
     (and e e)
     (concat e ...))
  (b ::= 0 1)
  (v ::= (b ...))
  (E ::= hole
     (and v E)
     (and E e)
     (concat v ... E e ...)))

(define red
  (reduction-relation
   L
   (--> (in-hole E (and (b_1 ...) (b_2 ...)))
        (in-hole E (concat (and (b_1) (b_2)) ...)))
   (--> (in-hole E (concat (b ...) ...))
        (in-hole E (b ... ...)))
   (--> (in-hole E (and (0) (b))) (in-hole E (0)))
   (--> (in-hole E (and (b) (0))) (in-hole E (0)))
   (--> (in-hole E (and (1) (1))) (in-hole E (1)))))


(traces
 red
 (term (and (1 0 1 0) (0 0 1 1))))

robby
2017-3-17 15:46:22

but now things go crazy.


robby
2017-3-17 15:46:39

indeed, there are infinite reduction sequences there that probably we don’t want.


robby
2017-3-17 15:47:04

I’ll let you try to fix that one, but the main hint is already there, namely that there is an overlap in the rules. Find the overlap and figure out which part you don’t really want.


robby
2017-3-17 15:47:20

Feel free to ask if you have more questions on this! I found it fun to work through this the first time I did it. :slightly_smiling_face:


stamourv
2017-3-17 16:48:35

@mflatt: Haven’t seen that. Will try it today.



ben
2017-3-17 16:50:44

ben
2017-3-17 16:51:08

“it took me a while to find a picture to describe ‘subject reduction’, but I think this one by Andy Warhol does the trick”


pnwamk
2017-3-17 17:04:44

for anyone reading this down the road — should be fixed by https://github.com/racket/typed-racket/pull/514


jeremy
2017-3-17 17:13:49

@jeremy has joined the channel


zeeshanlakhani
2017-3-17 17:20:30

@zeeshanlakhani has joined the channel


stamourv
2017-3-17 18:02:40

@pnwamk: Thanks!


leafac
2017-3-17 19:56:00

@robby: Thank you for your answer. I try to solve this and get back to you :slightly_smiling_face:


robby
2017-3-17 19:56:43

I had a lot of fund with that one :slightly_smiling_face:


leafac
2017-3-17 20:04:13

@robby: I think I get it. I changed the first rule in the reduction relation to only fire if the input lists are larger than 1. One way is to use a side-condition, or use more variables, like I did here:


leafac
2017-3-17 20:04:17
(--> (in-hole E (and (b_1 b_2 b_3 ...) (b_4 b_5 b_6 ...)))
        (in-hole E (concat (and (b_1) (b_4)) (and (b_2) (b_5)) (and (b_3) (b_6)) ...)))

robby
2017-3-17 20:04:41

right


leafac
2017-3-17 20:04:46

(Ideally, Redex would support …+ patterns, like syntax-parse. But it doesn’t.)


robby
2017-3-17 20:04:59

Well, now is the time when I point out the design constraints on Redex.


robby
2017-3-17 20:05:06

Namely that it match the way people write stuff in papers.


robby
2017-3-17 20:05:21

And …+ is not a common notation in the PL research papers, I would say.


robby
2017-3-17 20:05:27

Or, maybe it is, in which case I’d add it.


robby
2017-3-17 20:06:01

I suggest you try some random testing.


robby
2017-3-17 20:06:21

write somethign that translates arrays of booleans to numbers and then throw it at racket


robby
2017-3-17 20:06:34

(turn and into bitwise-and or whatever that function is called)


robby
2017-3-17 20:06:49

(turn and into bitwise-...... ….)


leafac
2017-3-17 20:06:58

:+1: I understand the design decision. It’s a good one :slightly_smiling_face: And there are always side-conditions.


robby
2017-3-17 20:07:02

you will find one bug that, I think.


robby
2017-3-17 20:07:14

Yes, a common thing in papers is something like


robby
2017-3-17 20:07:21

\|(b…)\| > 1 or something


robby
2017-3-17 20:07:36

And that’s just one typesetting rewrite away from a side-condition implmented via length.


robby
2017-3-17 20:07:42

(via racket’s length function)


leafac
2017-3-17 20:08:11

Sure :slightly_smiling_face:


andreiformiga
2017-3-17 20:13:08

@andreiformiga has joined the channel


leafac
2017-3-17 20:22:33

@robby:

> write somethign that translates arrays of booleans to numbers and then throw it at racket > (turn and into bitwise-and or whatever that function is called)

I understand you proposed something like the following:

(define-metafunction L
  reverse : (b ...) -> (b ...)
  [(reverse ()) ()]
  [(reverse (b_1 b_2 ...)) (b_3 ... b_1) (where (b_3 ...) (reverse (b_2 ...)))])

(define-metafunction L
  bs->integer : (b ...) -> integer
  [(bs->integer (b ...)) (bs->integer* (reverse (b ...)) 0)])

(define-metafunction L
  bs->integer* : (b ...) integer -> integer
  [(bs->integer* () integer) 0]
  [(bs->integer* (b_1 b_2 ...) integer)
   ,(+ (* (expt 2 (term integer)) (term b_1))
       (term (bs->integer* (b_2 ...) ,(add1 (term integer)))))])

(define red
  (reduction-relation
   L
   (--> (and (b_1 ...) (b_2 ...))
        ,(bitwise-and (term (bs->integer (b_1 ...))) (term (bs->integer (b_2 ...)))))))

But I believe my understanding is wrong. Can you clarify?