function x = restrictall(x,m)
% This function computes the restriction of a level m Y-network of
% resistors on SG to a single Y-circuit on the boundary points of SG
%
% support functions: ninetothree.m
%
% INPUT:
% x - vector of size 3^(m+1) holding resistances for Y-network 
% m - level of Y-network
%
% OUTPUT:
% 
%
% e.g. m = 1 is this map
%
%      |
%     / \        ->       |
%    |   |               / \
%   / \ / \

if(m == 1)
% if m = 1 we just restrict using ninetothree
  x = ninetothree(x) ;
else
% otherwise we recursively restrict to level one by calling on
% subcells, then use ninetothree
  x = [restrictall(x(1:3^(m-1),:),m-1); restrictall(x(3^(m-1)+1:2*3^(m-1),:),m-1); restrictall(x(2*3^(m-1)+1:3^m,:),m-1)] ;
  x = ninetothree(x) ;
end
