Comments (3)
Implemented in c0029ff, works with vscode plugin 0.0.33.
I also pitched in some extra generality. For example, an operation can be applied to multiple values picked from any number of arrays, possibly multiple values from each array, where some values are consumed and replaced and others are used as controls, given that a simple alias analysis can prove that the same value participates in the same operation at most once.
@marco-lewis You should be able to remove the workaround now. Just let me know if you run into any further issues or if you find some case where improving the alias analysis further would be helpful.
from silq.
Thanks for letting us know! This is indeed a feature that can/should/will be added, but I have not gotten around to implementing it.
Meanwhile, you can use one of the following workarounds:
Option 1: Procedural approach using CNOT:
n := 2;
def main(){
x:=0:uint[n];
// do some stuff to x
y:=0:uint[n];
// do some stuff to y
for i in 0..n{
// move (x[i], y[i]) out of array:
(a,b) := (x[i],y[i]);
x[i] := CNOT(a,x[i]);
y[i] := CNOT(b,y[i]);
// apply gate
(a,b) := W(a,b);
// move (a,b) back into array:
x[i] := CNOT(a,x[i]);
y[i] := CNOT(b,y[i]);
forget((a,b)=(x[i],y[i]));
}
return (x,y);
}
Option 2: Functional approach:
import util;
n:=2;
def main(){
x:=0:uint[n];
// do some stuff to x
y:=0:uint[n];
// do some stuff to y
(x,y):=unzip(map(W, zip(x as 𝔹^n,y as 𝔹^n))) as int[n]^2;
return (x,y);
}
Where util.slq contains the following helper functions:
def map[a,b,n:!ℕ](f: a!→mfree b, xs: a^n)mfree: b^n{
if n==0{ forget(xs=()); result := () coerce b^n; }
else { (x,)~xs:=xs; result := (f(x),)~map(f, xs); }
return result;
}
def zip[a,b,n:!ℕ](xs:a^n,ys:b^n)qfree:(a×b)^n{
xs:=xs:a[];
ys:=ys:b[];
r:=[]:(a×b)[];
repeat n{
(x,)~xs:=xs;
(y,)~ys:=ys;
r~=[(x,y)];
}
return r coerce (a×b)^n;
}
def unzip[a,b,n:!ℕ](xs:(a×b)^n)qfree:a^n×b^n{
xs:=xs:(a×b)[];
rs:=[]:a[];
qs:=[]:b[];
repeat n{
((r,q),)~xs:=xs;
rs~=[r];
qs~=[q];
}
return (rs,qs) coerce a^n×b^n;
}
from silq.
Good to hear, I'll use Option 1 for what I'm doing and hopefully will be able to replace it in the future.
from silq.
Related Issues (20)
- Small error in the documentation? HOT 2
- Cann't run silq in vscode HOT 4
- Error upon creating new files in vscode, can't use silq. HOT 2
- Silq REPL HOT 6
- Module imports HOT 2
- Constructing an array of parametrized length HOT 3
- build fails on AArch64 (A64FX), Fedora 33 HOT 2
- Compilation to circuits? HOT 3
- Adding docker support
- Functions on arrays? HOT 1
- Function calls omitting variables in square brackets causes errors when reversing HOT 2
- Does measurement or consciousness determine quantum state? HOT 2
- Quantum redefinition through quantum control behaviour inconsistent depending on scope HOT 2
- Method for resetting Quantum State HOT 1
- Is there any way to do actual things besides mathematical computation with silq? HOT 18
- Variable quantum state assignment HOT 2
- Please make a seperate package of silq for arch linux and it's derivatives
- Please elaborate the process to install silq in any arch linux derivative(specifically needed for blackarch linux). HOT 2
- Having troubles with running shor.slq (VS Code extension) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from silq.