// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.

// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package types

// A term describes elementary type sets:
//
//	 βˆ…:  (*term)(nil)     == βˆ…                      // set of no types (empty set)
//	 𝓀:  &term{}          == 𝓀                      // set of all types (𝓀niverse)
//	 T:  &term{false, T}  == {T}                    // set of type T
//	~t:  &term{true, t}   == {t' | under(t') == t}  // set of types with underlying type t
type term struct {
	tilde bool // valid if typ != nil
	typ   Type
}

func ( *term) () string {
	switch {
	case  == nil:
		return "βˆ…"
	case .typ == nil:
		return "𝓀"
	case .tilde:
		return "~" + .typ.String()
	default:
		return .typ.String()
	}
}

// equal reports whether x and y represent the same type set.
func ( *term) ( *term) bool {
	// easy cases
	switch {
	case  == nil ||  == nil:
		return  == 
	case .typ == nil || .typ == nil:
		return .typ == .typ
	}
	// βˆ… βŠ‚ x, y βŠ‚ 𝓀

	return .tilde == .tilde && Identical(.typ, .typ)
}

// union returns the union x βˆͺ y: zero, one, or two non-nil terms.
func ( *term) ( *term) (,  *term) {
	// easy cases
	switch {
	case  == nil &&  == nil:
		return nil, nil // βˆ… βˆͺ βˆ… == βˆ…
	case  == nil:
		return , nil // βˆ… βˆͺ y == y
	case  == nil:
		return , nil // x βˆͺ βˆ… == x
	case .typ == nil:
		return , nil // 𝓀 βˆͺ y == 𝓀
	case .typ == nil:
		return , nil // x βˆͺ 𝓀 == 𝓀
	}
	// βˆ… βŠ‚ x, y βŠ‚ 𝓀

	if .disjoint() {
		return ,  // x βˆͺ y == (x, y) if x ∩ y == βˆ…
	}
	// x.typ == y.typ

	// ~t βˆͺ ~t == ~t
	// ~t βˆͺ  T == ~t
	//  T βˆͺ ~t == ~t
	//  T βˆͺ  T ==  T
	if .tilde || !.tilde {
		return , nil
	}
	return , nil
}

// intersect returns the intersection x ∩ y.
func ( *term) ( *term) *term {
	// easy cases
	switch {
	case  == nil ||  == nil:
		return nil // βˆ… ∩ y == βˆ… and ∩ βˆ… == βˆ…
	case .typ == nil:
		return  // 𝓀 ∩ y == y
	case .typ == nil:
		return  // x ∩ 𝓀 == x
	}
	// βˆ… βŠ‚ x, y βŠ‚ 𝓀

	if .disjoint() {
		return nil // x ∩ y == βˆ… if x ∩ y == βˆ…
	}
	// x.typ == y.typ

	// ~t ∩ ~t == ~t
	// ~t ∩  T ==  T
	//  T ∩ ~t ==  T
	//  T ∩  T ==  T
	if !.tilde || .tilde {
		return 
	}
	return 
}

// includes reports whether t ∈ x.
func ( *term) ( Type) bool {
	// easy cases
	switch {
	case  == nil:
		return false // t ∈ βˆ… == false
	case .typ == nil:
		return true // t ∈ 𝓀 == true
	}
	// βˆ… βŠ‚ x βŠ‚ 𝓀

	 := 
	if .tilde {
		 = under()
	}
	return Identical(.typ, )
}

// subsetOf reports whether x βŠ† y.
func ( *term) ( *term) bool {
	// easy cases
	switch {
	case  == nil:
		return true // βˆ… βŠ† y == true
	case  == nil:
		return false // x βŠ† βˆ… == false since x != βˆ…
	case .typ == nil:
		return true // x βŠ† 𝓀 == true
	case .typ == nil:
		return false // 𝓀 βŠ† y == false since y != 𝓀
	}
	// βˆ… βŠ‚ x, y βŠ‚ 𝓀

	if .disjoint() {
		return false // x βŠ† y == false if x ∩ y == βˆ…
	}
	// x.typ == y.typ

	// ~t βŠ† ~t == true
	// ~t βŠ† T == false
	//  T βŠ† ~t == true
	//  T βŠ†  T == true
	return !.tilde || .tilde
}

// disjoint reports whether x ∩ y == βˆ….
// x.typ and y.typ must not be nil.
func ( *term) ( *term) bool {
	if debug && (.typ == nil || .typ == nil) {
		panic("invalid argument(s)")
	}
	 := .typ
	if .tilde {
		 = under()
	}
	 := .typ
	if .tilde {
		 = under()
	}
	return !Identical(, )
}