eth-sri / silq

Boost Software License 1.0
611 stars 52 forks source link

Silq REPL #17

Open ode opened 3 years ago

ode commented 3 years ago

I think it'd be great to have a repl for the language, for toying with code before writing it down. Shouldn't be too hard to implement (not too sure). Thoughts?

tgehr commented 3 years ago

Reading is easy, but it's not entirely clear how it would evaluate and print for quantum state. E.g.

> x:=H(0:๐”น);
???
> y:=dup(x);
???
> x
???
> dump()
/โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
QUANTUM STATE
(1+0i)ยท|1โŸฉโ‚€โŠ—|1โŸฉโ‚

VARIABLES
x โ†ฆ ref(0)
y โ†ฆ ref(1)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€/

How should this work? Otherwise, implementation should be pretty straightforward.

tgehr commented 3 years ago

Also, measurements can lead to destructive state updates, maybe there should be a way to undo them.

ode commented 3 years ago

well, clearly measurements shouldn't be done unless explicitly asked. Printing out the ket notation is a good alternative imo

tgehr commented 3 years ago

In my example, x and y are entangled, so I am not sure how to show the partial state. What would you show instead of ??? in the REPL output?

ode commented 3 years ago

we could either disregard entanglement and only show the probabilities or do something like

> x = H(0:๐”น);
(1/โˆš2) (|0โŸฉ + |1โŸฉ)

> y = dup(x);
|xyโŸฉ = (1/โˆš2) (|00โŸฉ + |11โŸฉ)

in other words, detecting variables that are entangled and showing all of them when one of them is asked. Note that x evaluates to the same thing after typing in the second statement

j6k4m8 commented 3 years ago

As a user I like the probability approach @LordPos mentions โ€” and I think for beginners it'll feel similar to what people have seen in tools like Quantum Experience etc!