當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Expr.Sort方法代碼示例

本文整理匯總了Golang中github.com/verdverm/go-symexpr.Expr.Sort方法的典型用法代碼示例。如果您正苦於以下問題:Golang Expr.Sort方法的具體用法?Golang Expr.Sort怎麽用?Golang Expr.Sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/verdverm/go-symexpr.Expr的用法示例。


在下文中一共展示了Expr.Sort方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ExpandMethod1

func (PS *PgeSearch) ExpandMethod1(O expr.Expr) (ret []expr.Expr) {
	O.Sort()
	ret = make([]expr.Expr, 0)
	// fmt.Printf("Expanding expression:  %v\n", O)

	for i := 0; i < O.Size(); i++ {
		I := i
		E := O.GetExpr(&I)
		switch E.ExprType() {
		case expr.ADD:
			tmp := PS.AddTermToExprMethod1(O, E, i)
			ret = append(ret, tmp[:]...)

		case expr.MUL:
			tmp := PS.WidenTermInExprMethod1(O, E, i)
			ret = append(ret, tmp[:]...)

		case expr.VAR:
			tmp := PS.DeepenTermInExprMethod1(O, E, i)
			ret = append(ret, tmp[:]...)

		default: // expr.DIV,expr.COS,expr.SIN,expr.EXP,expr.LOG,expr.ABS,expr.POW
			continue

		}
	}

	return ret
}
開發者ID:verdverm,項目名稱:go-pge,代碼行數:29,代碼來源:pge_expand_method_1.go

示例2: ExpandMethod3

func (PS *PgeSearch) ExpandMethod3(O expr.Expr) (ret []expr.Expr) {
	O.Sort()
	ret = make([]expr.Expr, 0)
	// fmt.Printf("Expanding expression:  %v\n", O)

	add := O.(*expr.Add)

	// adding term to addition
	for _, B := range PS.ffxBases {
		found := false
		for _, C := range add.CS {
			// fmt.Printf("checking %v in %v\n", B, add)
			if C.AmISame(B) {
				// fmt.Println("found\n\n")
				found = true
				break
			}
		}
		if !found {
			e := O.Clone()
			a := e.(*expr.Add)
			a.Insert(B.Clone())
			sort.Sort(a)
			a.CalcExprStats()
			good := PS.cnfg.treecfg.CheckExpr(a)
			if good {
				ret = append(ret, a)
			}
			// fmt.Printf("grew  %v\n\n", a)
			// ret = append(ret, a)
		}
	}

	// extending terms in addition
	for _, B := range PS.ffxBases {
		for i, C := range add.CS {
			if C.ExprType() == expr.MUL {
				m := C.(*expr.Mul)
				if len(m.CS) > 3 {
					continue
				}
			}
			e := O.Clone()
			a := e.(*expr.Add)
			mul := expr.NewMul()
			mul.Insert(a.CS[i])
			mul.Insert(B.Clone())
			a.CS[i] = mul
			sort.Sort(a)
			a.CalcExprStats()
			good := PS.cnfg.treecfg.CheckExpr(a)
			if good {
				ret = append(ret, a)
			}
			// fmt.Printf("grew  %v\n\n", a)
			ret = append(ret, a)
		}
	}

	// fmt.Println("Len of ret = ", len(ret))
	return ret
}
開發者ID:verdverm,項目名稱:go-pge,代碼行數:62,代碼來源:pge_expand_method_3.go

示例3: ExpandMethod2

func (PS *PgeSearch) ExpandMethod2(O expr.Expr) (ret []expr.Expr) {
	O.Sort()
	ret = make([]expr.Expr, 0)
	// fmt.Printf("Expanding expression:  %v\n", O)

	add := O.(*expr.Add)

	// adding term to addition
	for _, B := range PS.ffxBases {
		found := false
		for _, C := range add.CS {
			// fmt.Printf("checking %v in %v\n", B, add)
			if C.AmISame(B) {
				// fmt.Println("found\n\n")
				found = true
				break
			}
		}
		if !found {
			e := O.Clone()
			a := e.(*expr.Add)
			a.Insert(B.Clone())
			sort.Sort(a)
			a.CalcExprStats()
			good := PS.cnfg.treecfg.CheckExpr(a)
			if good {
				ret = append(ret, a)
			}
			// fmt.Printf("grew  %v\n\n", a)
			// ret = append(ret, a)
		}
	}

	// extending terms in addition
	for _, B := range PS.ffxBases {
		for i, C := range add.CS {
			if C.ExprType() == expr.MUL {
				m := C.(*expr.Mul)
				if len(m.CS) > 3 {
					continue
				}
			}
			e := O.Clone()
			a := e.(*expr.Add)
			mul := expr.NewMul()
			mul.Insert(a.CS[i])
			mul.Insert(B.Clone())
			a.CS[i] = mul
			sort.Sort(a)
			a.CalcExprStats()
			good := PS.cnfg.treecfg.CheckExpr(a)
			if good {
				ret = append(ret, a)
			}
			// fmt.Printf("grew  %v\n\n", a)
			ret = append(ret, a)
		}
	}

	// deepening terms
	// if len(add.CS) < 2 {
	// 	return ret
	// }
	for i, C := range add.CS {
		if C.ExprType() == expr.MUL {
			m := C.(*expr.Mul)
			if len(m.CS) != 2 {
				continue
			}
			if m.CS[1].ExprType() == expr.ADD {
				continue
			}
		} else {
			continue
		}

		for _, B := range PS.ffxBases {
			e := O.Clone()
			a := e.(*expr.Add)
			m := a.CS[i].(*expr.Mul)
			n := m.CS[1]

			switch n.ExprType() {
			case expr.SQRT:
				A := expr.NewAdd()
				A.Insert(n.(*expr.Sqrt).C)
				A.Insert(B.Clone())
				n.(*expr.Sqrt).C = A
			case expr.SIN:
				A := expr.NewAdd()
				A.Insert(n.(*expr.Sin).C)
				A.Insert(B.Clone())
				n.(*expr.Sin).C = A
			case expr.COS:
				A := expr.NewAdd()
				A.Insert(n.(*expr.Cos).C)
				A.Insert(B.Clone())
				n.(*expr.Cos).C = A
			case expr.TAN:
				A := expr.NewAdd()
//.........這裏部分代碼省略.........
開發者ID:verdverm,項目名稱:go-pge,代碼行數:101,代碼來源:pge_expand_method_2.go


注:本文中的github.com/verdverm/go-symexpr.Expr.Sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。