Giter VIP home page Giter VIP logo

Comments (3)

tgehr avatar tgehr commented on August 18, 2024 1

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.

tgehr avatar tgehr commented on August 18, 2024

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.

marco-lewis avatar marco-lewis commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.