code: func Optimize(s Shape, qs graph.QuadStore) (Shape, bool) {
  	if s == nil {
  		return nil, false
  	}
  	qs = graph.Unwrap(qs)
  	var opt bool
  	if qs != nil {
  		// resolve all lookups earlier
  		s, opt = s.Optimize(resolveValues{qs: qs})
  	}
  	if s == nil {
  		return Null{}, true
  	}
  	// generic optimizations
  	var opt1 bool
  	s, opt1 = s.Optimize(nil)
  	if s == nil {
  		return Null{}, true
  	}
  	opt = opt || opt1
  	// apply quadstore-specific optimizations
  	if so, ok := qs.(Optimizer); ok && s != nil {
  		var opt2 bool
  		s, opt2 = s.Optimize(so)
  		opt = opt || opt2
  	}
  	if s == nil {
  		return Null{}, true
  	}
  	return s, opt
  }
docs: // Optimize applies generic optimizations for the tree.
  // If quad store is specified it will also resolve Lookups and apply any specific optimizations.
  // Should not be used with Simplify - it will fold query to a compact form again.