diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 00000000..91e22777 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,36 @@ +name: Lint + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + Linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + - uses: actions/setup-go@v3 + with: + go-version: '>=1.22.0' + - run: go install golang.org/x/tools/cmd/goyacc@latest + - run: cd src && make + - uses: rrbutani/use-nix-shell-action@v1 + with: + file: shell.nix + script: | + failure=0 + for f in `find . -type f -name "src/*.go"`; do + if [[ ! -z `cmp $f <(golines -m 100 $f)` ]]; then + echo "$f is not properly formatted." + failure=1 + fi + done + + exit $failure diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a3632354..7b987927 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,29 @@ master*. If you are solving a bug referenced in the issue tracker, do not forget to link it in the PR. +### Code formatting + +We expect the code to be formatted using the `golines` tool, with the linebreak configured +at *100* characters. `golines` is furnished in the Nix environment, but can otherwise be +installed by following the instructions of the [official +repository](https://github.com/golangci/golines). You can enable `golines` to run on save +in your IDE. + +#### Formatting on save in `emacs` + +```elisp +(use-package go-mode + :init + (defun my/go-format () + (interactive) + (when (eq major-mode 'go-mode) + (shell-command + (format "golines -m 100 -w %s" buffer-file-name)))) + + :hook ((after-save-hook . my/go-format))) +``` +Moreover, if you don't have the `auto-revert-mode` enabled globally, you should probably hook it to `go-mode`. + ### Error management When you add code or fix old code, try to find the possible error cases where an diff --git a/shell.nix b/shell.nix index 121645eb..b9ee36d0 100644 --- a/shell.nix +++ b/shell.nix @@ -5,6 +5,7 @@ pkgs.mkShell { go gopls gotools + golines python314 rocq-core ocamlPackages.lambdapi diff --git a/src/AST/formsDef.go b/src/AST/formsDef.go index e6839766..c4c607b4 100644 --- a/src/AST/formsDef.go +++ b/src/AST/formsDef.go @@ -101,7 +101,8 @@ func MakerAll(vars []Var, forms Form) All { func (a All) Equals(other any) bool { if typed, ok := other.(All); ok { - return AreEqualsVarList(a.GetVarList(), typed.GetVarList()) && a.GetForm().Equals(typed.GetForm()) + return AreEqualsVarList(a.GetVarList(), typed.GetVarList()) && + a.GetForm().Equals(typed.GetForm()) } return false @@ -157,7 +158,8 @@ func MakerEx(vars []Var, forms Form) Ex { func (e Ex) Equals(other any) bool { if typed, ok := other.(Ex); ok { - return AreEqualsVarList(e.GetVarList(), typed.GetVarList()) && e.GetForm().Equals(typed.GetForm()) + return AreEqualsVarList(e.GetVarList(), typed.GetVarList()) && + e.GetForm().Equals(typed.GetForm()) } return false @@ -239,7 +241,13 @@ func (a AllType) GetType() TypeScheme { return DefaultPropType(0) } /* Form interface */ func (a AllType) ToMappedString(mapping MapString, displayTypes bool) string { - return mapping[QuantVarOpen] + Glob.ListToString(a.GetVarList(), ", ", "") + " : " + mapping[TypeVarType] + mapping[QuantVarClose] + mapping[QuantVarSep] + " (" + a.GetForm().ToString() + ")" + return mapping[QuantVarOpen] + Glob.ListToString( + a.GetVarList(), + ", ", + "", + ) + " : " + mapping[TypeVarType] + mapping[QuantVarClose] + mapping[QuantVarSep] + " (" + a.GetForm(). + ToString() + + ")" } func (a AllType) ToString() string { @@ -247,10 +255,17 @@ func (a AllType) ToString() string { } func (a AllType) ToMappedStringSurround(mapping MapString, displayTypes bool) string { - return "(" + mapping[AllTypeQuant] + " " + mapping[QuantVarOpen] + Glob.ListToString(a.GetVarList(), ", ", "") + " : " + mapping[TypeVarType] + mapping[QuantVarClose] + mapping[QuantVarSep] + " (%s))" + return "(" + mapping[AllTypeQuant] + " " + mapping[QuantVarOpen] + Glob.ListToString( + a.GetVarList(), + ", ", + "", + ) + " : " + mapping[TypeVarType] + mapping[QuantVarClose] + mapping[QuantVarSep] + " (%s))" } -func (a AllType) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (a AllType) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return "", "" } @@ -406,7 +421,10 @@ func (o Or) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "(%s)" } -func (o Or) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (o Or) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return " " + mapping[OrConn] + " ", "" } @@ -474,8 +492,13 @@ func MakeAndSimpleBinary(i int, forms *FormList, metas Lib.Set[Meta]) And { default: return MakeAndSimple( i, - NewFormList([]Form{forms.Get(0), MakerAnd(NewFormList(forms.GetElements(1, forms.Len())...), true)}...), - metas) + NewFormList( + []Form{ + forms.Get(0), + MakerAnd(NewFormList(forms.GetElements(1, forms.Len())...), true), + }...), + metas, + ) } } @@ -549,7 +572,10 @@ func (a And) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "(%s)" } -func (a And) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (a And) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return " " + mapping[AndConn] + " ", "" } @@ -626,7 +652,10 @@ func (e Equ) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "(%s)" } -func (e Equ) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (e Equ) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return " " + mapping[EquConn] + " ", "" } @@ -671,7 +700,11 @@ func (e Equ) Equals(f any) bool { } func (e Equ) ReplaceTypeByMeta(varList []TypeVar, index int) Form { - return MakeEqu(e.GetIndex(), e.GetF1().ReplaceTypeByMeta(varList, index), e.GetF2().ReplaceTypeByMeta(varList, index)) + return MakeEqu( + e.GetIndex(), + e.GetF1().ReplaceTypeByMeta(varList, index), + e.GetF2().ReplaceTypeByMeta(varList, index), + ) } func (e Equ) ReplaceTermByTerm(old Term, new Term) (Form, bool) { @@ -711,7 +744,11 @@ func (e Equ) GetChildFormulas() *FormList { } func (e Equ) ReplaceMetaByTerm(meta Meta, term Term) Form { - return MakeEqu(e.GetIndex(), e.f1.ReplaceMetaByTerm(meta, term), e.f2.ReplaceMetaByTerm(meta, term)) + return MakeEqu( + e.GetIndex(), + e.f1.ReplaceMetaByTerm(meta, term), + e.f2.ReplaceMetaByTerm(meta, term), + ) } // ----------------------------------------------------------------------------- @@ -749,7 +786,10 @@ func (i Imp) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "(%s)" } -func (i Imp) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (i Imp) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return " " + mapping[ImpConn] + " ", "" } @@ -796,7 +836,11 @@ func (i Imp) Equals(other any) bool { } func (i Imp) ReplaceTypeByMeta(varList []TypeVar, index int) Form { - return MakeImp(i.GetIndex(), i.GetF1().ReplaceTypeByMeta(varList, index), i.GetF2().ReplaceTypeByMeta(varList, index)) + return MakeImp( + i.GetIndex(), + i.GetF1().ReplaceTypeByMeta(varList, index), + i.GetF2().ReplaceTypeByMeta(varList, index), + ) } func (i Imp) ReplaceTermByTerm(old Term, new Term) (Form, bool) { @@ -837,7 +881,11 @@ func (i Imp) GetChildFormulas() *FormList { } func (i Imp) ReplaceMetaByTerm(meta Meta, term Term) Form { - return MakeImp(i.GetIndex(), i.f1.ReplaceMetaByTerm(meta, term), i.f2.ReplaceMetaByTerm(meta, term)) + return MakeImp( + i.GetIndex(), + i.f1.ReplaceMetaByTerm(meta, term), + i.f2.ReplaceMetaByTerm(meta, term), + ) } // ----------------------------------------------------------------------------- @@ -915,7 +963,10 @@ func (n Not) ToMappedStringSurround(mapping MapString, displayTypes bool) string return mapping[NotConn] + "(%s)" } -func (n Not) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (n Not) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return "", "" } @@ -1093,10 +1144,18 @@ func (p Pred) ToMappedStringSurround(mapping MapString, displayTypes bool) strin return "(" + strings.Join(args, " "+mapping[PredTypeVarSep]+" ") + ")" } - return p.GetID().ToMappedString(mapping, displayTypes) + "(" + strings.Join(args, " "+mapping[PredTypeVarSep]+" ") + ")" + return p.GetID(). + ToMappedString(mapping, displayTypes) + + "(" + strings.Join( + args, + " "+mapping[PredTypeVarSep]+" ", + ) + ")" } -func (p Pred) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (p Pred) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { if p.GetID().GetName() == "=" { return " = ", mapping[PredEmpty] } @@ -1274,7 +1333,10 @@ func (t Top) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "%s" } -func (t Top) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (t Top) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return "", mapping[TopType] } @@ -1318,7 +1380,10 @@ func (b Bot) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "%s" } -func (b Bot) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (b Bot) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return "", mapping[BotType] } diff --git a/src/AST/maker.go b/src/AST/maker.go index 1289206e..285a353e 100644 --- a/src/AST/maker.go +++ b/src/AST/maker.go @@ -157,7 +157,13 @@ func MakerMeta(s string, formula int, t ...TypeApp) Meta { /* Const maker (given a id, create a fun without args) */ func MakerConst(id Id, t ...TypeApp) Fun { - return MakeFun(id, Lib.NewList[Term](), []TypeApp{}, getType(t).(TypeScheme), Lib.EmptySet[Meta]()) + return MakeFun( + id, + Lib.NewList[Term](), + []TypeApp{}, + getType(t).(TypeScheme), + Lib.EmptySet[Meta](), + ) } /* Fun maker, with given id and args */ diff --git a/src/AST/manage_apps_types.go b/src/AST/manage_apps_types.go index 06b6bbb9..4468d022 100644 --- a/src/AST/manage_apps_types.go +++ b/src/AST/manage_apps_types.go @@ -83,13 +83,19 @@ func SaveTypeScheme(name string, in TypeApp, out TypeApp) error { if tScheme.Equals(tArrow) { return nil } - return fmt.Errorf("trying to save a known type scheme with different return types for the function %s", name) + return fmt.Errorf( + "trying to save a known type scheme with different return types for the function %s", + name, + ) } // It's not in the map, it should be added typeSchemesMap.lock.Lock() if found { - typeSchemesMap.tsMap[name] = append(typeSchemesMap.tsMap[name], App{in: in, out: out, App: tArrow}) + typeSchemesMap.tsMap[name] = append( + typeSchemesMap.tsMap[name], + App{in: in, out: out, App: tArrow}, + ) } else { typeSchemesMap.tsMap[name] = []App{{in: in, out: out, App: tArrow}} } @@ -102,7 +108,10 @@ func SavePolymorphScheme(name string, scheme TypeScheme) error { tScheme, found := getPolymorphSchemeFromArgs(name, scheme) if tScheme != nil { if !GetOutType(tScheme).Equals(GetOutType(scheme)) { - return fmt.Errorf("trying to save a known type scheme with different return types for the function %s", name) + return fmt.Errorf( + "trying to save a known type scheme with different return types for the function %s", + name, + ) } return nil } @@ -126,7 +135,10 @@ func SaveConstant(name string, out TypeApp) error { if arr, found := typeSchemesMap.tsMap[name]; found { var err error if !arr[0].out.Equals(out) { - err = fmt.Errorf("trying to save a known type scheme with different return types for the function %s", name) + err = fmt.Errorf( + "trying to save a known type scheme with different return types for the function %s", + name, + ) } typeSchemesMap.lock.Unlock() return err @@ -190,7 +202,8 @@ func GetPolymorphicType(name string, lenVars, lenTerms int) TypeScheme { typeSchemesMap.lock.Lock() if arr, found := typeSchemesMap.tsMap[name]; found { for _, fun := range arr { - if fun.App.Size()-1 == lenTerms && (Glob.Is[QuantifiedType](fun.App) && len(fun.App.(QuantifiedType).vars) == lenVars) { + if fun.App.Size()-1 == lenTerms && + (Glob.Is[QuantifiedType](fun.App) && len(fun.App.(QuantifiedType).vars) == lenVars) { typeSchemesMap.lock.Unlock() return fun.App } diff --git a/src/AST/mapped_strings.go b/src/AST/mapped_strings.go index 1496913e..f137d9f2 100644 --- a/src/AST/mapped_strings.go +++ b/src/AST/mapped_strings.go @@ -123,11 +123,22 @@ func (fms MappedString) ToString() string { func (fms MappedString) ToMappedString(mapping MapString, displayType bool) string { surround := fms.ToMappedStringSurround(mapping, displayType) separator, emptyValue := fms.ToMappedStringChild(mapping, displayType) - children := ListToMappedString(fms.GetChildrenForMappedString(), separator, emptyValue, mapping, displayType) + children := ListToMappedString( + fms.GetChildrenForMappedString(), + separator, + emptyValue, + mapping, + displayType, + ) return fmt.Sprintf(surround, children) } -func ListToMappedString[T MappableString](sgbl []T, separator, emptyValue string, mapping MapString, displayTypes bool) string { +func ListToMappedString[T MappableString]( + sgbl []T, + separator, emptyValue string, + mapping MapString, + displayTypes bool, +) string { strArr := []string{} for _, element := range sgbl { @@ -163,7 +174,10 @@ func (ssm *SimpleStringMappable) ToMappedStringSurround(MapString, bool) string return "" } -func (ssm *SimpleStringMappable) ToMappedStringChild(MapString, bool) (separator string, emptyValue string) { +func (ssm *SimpleStringMappable) ToMappedStringChild( + MapString, + bool, +) (separator string, emptyValue string) { return "", "" } diff --git a/src/AST/parameterizedtype.go b/src/AST/parameterizedtype.go index 5b2d4a42..4ce040a5 100644 --- a/src/AST/parameterizedtype.go +++ b/src/AST/parameterizedtype.go @@ -41,6 +41,7 @@ import ( "strings" "fmt" + "github.com/GoelandProver/Goeland/Glob" "github.com/GoelandProver/Goeland/Lib" ) @@ -107,7 +108,10 @@ func (pt ParameterizedType) GetParameters() []TypeApp { } func (pt ParameterizedType) Copy() TypeApp { - newPT := ParameterizedType{name: pt.name, parameters: make(Lib.ComparableList[TypeApp], len(pt.parameters))} + newPT := ParameterizedType{ + name: pt.name, + parameters: make(Lib.ComparableList[TypeApp], len(pt.parameters)), + } copy(newPT.parameters, pt.parameters) return newPT } @@ -131,8 +135,14 @@ func MkParameterizedType(name string, types []TypeApp) ParameterizedType { } if k != len(types) { pMap.lock.Unlock() - Glob.PrintInfo("PRMTR_TYPE", fmt.Sprintf("Name of the type: %s, length of the args: %d", name, len(types))) - Glob.PrintError("PRMTR_TYPE", "Parameterized type can not be instanciated with this number of arguments.") + Glob.PrintInfo( + "PRMTR_TYPE", + fmt.Sprintf("Name of the type: %s, length of the args: %d", name, len(types)), + ) + Glob.PrintError( + "PRMTR_TYPE", + "Parameterized type can not be instanciated with this number of arguments.", + ) return ParameterizedType{} } types = nextTypes diff --git a/src/AST/quantifiedtype.go b/src/AST/quantifiedtype.go index 2394c58e..5d4c6320 100644 --- a/src/AST/quantifiedtype.go +++ b/src/AST/quantifiedtype.go @@ -57,7 +57,12 @@ type QuantifiedType struct { /* TypeScheme interface */ func (qt QuantifiedType) isScheme() {} func (qt QuantifiedType) toMappedString(subst map[string]string) string { - return "Π " + strings.Join(convert(qt.vars, typeTToString[TypeVar]), ", ") + ": Type. " + qt.scheme.toMappedString(subst) + return "Π " + strings.Join( + convert(qt.vars, typeTToString[TypeVar]), + ", ", + ) + ": Type. " + qt.scheme.toMappedString( + subst, + ) } func (qt QuantifiedType) Equals(oth interface{}) bool { @@ -121,7 +126,10 @@ func (qt QuantifiedType) Instanciate(types []TypeApp) TypeScheme { if Glob.Is[TypeApp](qt.scheme) { if len(tv) > 0 { - return MkQuantifiedType(tv, Glob.To[TypeScheme](Glob.To[TypeApp](qt.scheme).instanciate(substMap))) + return MkQuantifiedType( + tv, + Glob.To[TypeScheme](Glob.To[TypeApp](qt.scheme).instanciate(substMap)), + ) } return Glob.To[TypeScheme](Glob.To[TypeApp](qt.scheme).instanciate(substMap)) } else if Glob.Is[TypeArrow](qt.scheme) { diff --git a/src/AST/quantifiers.go b/src/AST/quantifiers.go index 3f9ca9f0..4692feaf 100644 --- a/src/AST/quantifiers.go +++ b/src/AST/quantifiers.go @@ -53,7 +53,13 @@ type quantifier struct { symbol FormulaType } -func makeQuantifier(i int, vars []Var, subForm Form, metas Lib.Set[Meta], symbol FormulaType) quantifier { +func makeQuantifier( + i int, + vars []Var, + subForm Form, + metas Lib.Set[Meta], + symbol FormulaType, +) quantifier { fms := &MappedString{} qua := quantifier{ fms, @@ -96,7 +102,10 @@ func (q quantifier) ToString() string { return q.MappedString.ToString() } -func (q quantifier) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (q quantifier) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return " ", "" } @@ -139,7 +148,10 @@ func (q quantifier) ToMappedStringSurround(mapping MapString, displayTypes bool) varStrings = append(varStrings, str+mapping[QuantVarClose]) } - return "(" + mapping[q.symbol] + " " + strings.Join(varStrings, " ") + mapping[QuantVarSep] + " (%s))" + return "(" + mapping[q.symbol] + " " + strings.Join( + varStrings, + " ", + ) + mapping[QuantVarSep] + " (%s))" } func (q quantifier) GetChildrenForMappedString() []MappableString { diff --git a/src/AST/termsDef.go b/src/AST/termsDef.go index 8b240000..ef1c8a9a 100644 --- a/src/AST/termsDef.go +++ b/src/AST/termsDef.go @@ -72,7 +72,10 @@ func (i Id) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "%s" } -func (i Id) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (i Id) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return "", ToStringId(i) } @@ -154,14 +157,25 @@ type Fun struct { } func (f Fun) ToMappedStringSurround(mapping MapString, displayTypes bool) string { - return f.ToMappedStringSurroundWithId(f.GetID().ToMappedString(mapping, displayTypes), mapping, displayTypes) + return f.ToMappedStringSurroundWithId( + f.GetID().ToMappedString(mapping, displayTypes), + mapping, + displayTypes, + ) } -func (f Fun) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (f Fun) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { return ", ", mapping[PredEmpty] } -func (f Fun) ToMappedStringSurroundWithId(idString string, mapping MapString, displayTypes bool) string { +func (f Fun) ToMappedStringSurroundWithId( + idString string, + mapping MapString, + displayTypes bool, +) string { if len(f.typeVars) == 0 && f.GetArgs().Len() == 0 { return idString + "%s" } @@ -182,7 +196,12 @@ func (f Fun) ToMappedStringSurroundWithId(idString string, mapping MapString, di return str } -func ToFlatternStringSurrountWithId(f Fun, idString string, mapping MapString, displayTypes bool) string { +func ToFlatternStringSurrountWithId( + f Fun, + idString string, + mapping MapString, + displayTypes bool, +) string { if len(f.typeVars) == 0 && f.GetArgs().Len() == 0 { return idString + "%s" @@ -241,11 +260,23 @@ func (f Fun) Equals(t any) bool { } func (f Fun) Copy() Term { - return MakeFun(f.GetP(), f.GetArgs(), CopyTypeAppList(f.GetTypeVars()), f.GetTypeHint(), f.metas.Raw()) + return MakeFun( + f.GetP(), + f.GetArgs(), + CopyTypeAppList(f.GetTypeVars()), + f.GetTypeHint(), + f.metas.Raw(), + ) } func (f Fun) PointerCopy() *Fun { - nf := MakeFun(f.GetP(), f.GetArgs(), CopyTypeAppList(f.GetTypeVars()), f.GetTypeHint(), f.metas.Raw()) + nf := MakeFun( + f.GetP(), + f.GetArgs(), + CopyTypeAppList(f.GetTypeVars()), + f.GetTypeHint(), + f.metas.Raw(), + ) return &nf } @@ -375,7 +406,10 @@ func (v Var) ToMappedStringSurround(mapping MapString, displayTypes bool) string return "%s" } -func (v Var) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (v Var) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { if displayTypes { return "", fmt.Sprintf("%s_%d : %s", v.GetName(), v.GetIndex(), v.typeHint.ToString()) } else { @@ -426,7 +460,10 @@ func (m Meta) ToMappedStringSurround(mapping MapString, displayTypes bool) strin return "%s" } -func (m Meta) ToMappedStringChild(mapping MapString, displayTypes bool) (separator, emptyValue string) { +func (m Meta) ToMappedStringChild( + mapping MapString, + displayTypes bool, +) (separator, emptyValue string) { if displayTypes { return "", fmt.Sprintf("%s_%d : %s", m.GetName(), m.GetIndex(), m.GetTypeHint().ToString()) } else { diff --git a/src/AST/typearrow.go b/src/AST/typearrow.go index 6690f424..25b9225b 100644 --- a/src/AST/typearrow.go +++ b/src/AST/typearrow.go @@ -70,7 +70,9 @@ func (ta TypeArrow) toMappedString(subst map[string]string) string { /* TypeArrow methods */ func (ta TypeArrow) substitute(mapSubst map[TypeVar]string) TypeScheme { - return MkTypeArrow(ta.left.substitute(mapSubst).(TypeApp), substTypeAppList(mapSubst, ta.right)...) + return MkTypeArrow( + ta.left.substitute(mapSubst).(TypeApp), + substTypeAppList(mapSubst, ta.right)...) } func (ta TypeArrow) instanciate(mapSubst map[TypeVar]TypeApp) TypeScheme { return MkTypeArrow(ta.left.instanciate(mapSubst), instanciateList(mapSubst, ta.right)...) @@ -92,7 +94,8 @@ func (ta TypeArrow) Equals(oth interface{}) bool { } othTA := Glob.To[TypeArrow](oth) - return ((ta.left == nil && othTA.left == nil) || ta.left.Equals(othTA.left)) && ta.right.Equals(othTA.right) + return ((ta.left == nil && othTA.left == nil) || ta.left.Equals(othTA.left)) && + ta.right.Equals(othTA.right) } func (ta TypeArrow) Size() int { @@ -108,7 +111,11 @@ func (ta TypeArrow) GetPrimitives() []TypeApp { /* Makes a TypeArrow from two TypeSchemes */ func MkTypeArrow(left TypeApp, typeApps ...TypeApp) TypeArrow { if len(typeApps) < 1 { - debug(Lib.MkLazy(func() string { return "There should be at least one out type in a TypeArrow." })) + debug( + Lib.MkLazy( + func() string { return "There should be at least one out type in a TypeArrow." }, + ), + ) return TypeArrow{} } ta := TypeArrow{left: left, right: make(Lib.ComparableList[TypeApp], len(typeApps))} diff --git a/src/AST/typecross.go b/src/AST/typecross.go index 73466cb1..952bb916 100644 --- a/src/AST/typecross.go +++ b/src/AST/typecross.go @@ -120,7 +120,11 @@ func (tc TypeCross) GetAllUnderlyingTypes() []TypeApp { **/ func MkTypeCross(typeSchemes ...TypeApp) TypeCross { if len(typeSchemes) < 2 { - debug(Lib.MkLazy(func() string { return "There should be at least two underlying types in a TypeCross." })) + debug( + Lib.MkLazy( + func() string { return "There should be at least two underlying types in a TypeCross." }, + ), + ) return TypeCross{} } tc := TypeCross{types: make([]TypeApp, len(typeSchemes))} diff --git a/src/Core/global_unifier.go b/src/Core/global_unifier.go index 3657dca0..203a1bcb 100644 --- a/src/Core/global_unifier.go +++ b/src/Core/global_unifier.go @@ -92,7 +92,10 @@ func (u *Unifier) AddSubstitutions(cleanedSubst, actualSubst substitutions) { } } if !found { - u.localUnifiers = append(u.localUnifiers, Glob.MakePair(cleanedSubst, []substitutions{actualSubst})) + u.localUnifiers = append( + u.localUnifiers, + Glob.MakePair(cleanedSubst, []substitutions{actualSubst}), + ) } } @@ -120,9 +123,15 @@ func (u Unifier) ToString() string { } str := "object Unifier{" for _, unifier := range u.localUnifiers { - str += "[ " + strings.Join(Glob.MapTo(unifier.Fst, substsToString), ", ") + " ] --> [ " + strings.Join(Glob.MapTo(unifier.Snd, func(_ int, el substitutions) string { - return strings.Join(Glob.MapTo(el, substsToString), " ; ") - }), " ---- ") + " ], " + str += "[ " + strings.Join( + Glob.MapTo(unifier.Fst, substsToString), + ", ", + ) + " ] --> [ " + strings.Join( + Glob.MapTo(unifier.Snd, func(_ int, el substitutions) string { + return strings.Join(Glob.MapTo(el, substsToString), " ; ") + }), + " ---- ", + ) + " ], " } str += "}" return str @@ -163,7 +172,9 @@ func (u *Unifier) Merge(other Unifier) { } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Current: %s, to merge: %s", u.ToString(), other.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Current: %s, to merge: %s", u.ToString(), other.ToString()) }, + ), ) newUnifiers := []Glob.Pair[substitutions, []substitutions]{} @@ -212,7 +223,11 @@ func (u *Unifier) PruneMetasInSubsts(metas Lib.Set[AST.Meta]) { u.localUnifiers = newUnifiers } -func appendNewUnifiersIfNeeded(unifiers []Glob.Pair[substitutions, []substitutions], res substitutions, newUnifs []substitutions) []Glob.Pair[substitutions, []substitutions] { +func appendNewUnifiersIfNeeded( + unifiers []Glob.Pair[substitutions, []substitutions], + res substitutions, + newUnifs []substitutions, +) []Glob.Pair[substitutions, []substitutions] { for i, unif := range unifiers { if unif.Fst.Equals(res) { unifiers[i].Snd = append(unifiers[i].Snd, newUnifs...) diff --git a/src/Core/meta_gen.go b/src/Core/meta_gen.go index 00008c4a..1b226ce6 100644 --- a/src/Core/meta_gen.go +++ b/src/Core/meta_gen.go @@ -121,7 +121,8 @@ func chooseLessReintroducedMeta(meta_generator []MetaGen, allowed_indexes []int) saved_cpt := -1 saved_index := 0 for i, v := range meta_generator { - if (allowed_indexes == nil || Glob.ContainsInt(i, allowed_indexes)) && ((v.GetCounter() < saved_cpt) || saved_cpt == -1) { + if (allowed_indexes == nil || Glob.ContainsInt(i, allowed_indexes)) && + ((v.GetCounter() < saved_cpt) || saved_cpt == -1) { saved_index = i saved_cpt = v.GetCounter() } @@ -135,9 +136,12 @@ func getAllLessReintroducedMeta(meta_generator []MetaGen, allowed_indexes []int) saved_indexes := []int{} for i, v := range meta_generator { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("v.getCounter : %d - Min : %d", v.GetCounter(), min) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("v.getCounter : %d - Min : %d", v.GetCounter(), min) }, + ), ) - if (allowed_indexes == nil || Glob.ContainsInt(i, allowed_indexes)) && ((v.GetCounter() <= min) || min == -1) { + if (allowed_indexes == nil || Glob.ContainsInt(i, allowed_indexes)) && + ((v.GetCounter() <= min) || min == -1) { new_min := v.GetCounter() if new_min < min || min == -1 { saved_indexes = []int{i} @@ -158,7 +162,10 @@ func getAllLessReintroducedMeta(meta_generator []MetaGen, allowed_indexes []int) **/ func ReintroduceMeta(meta_generator *[]MetaGen, index int, limit int) FormAndTerms { if index != -1 && (*meta_generator)[index].GetCounter() <= limit { - (*meta_generator)[index] = MakeMetaGen((*meta_generator)[index].GetForm(), (*meta_generator)[index].GetCounter()+1) + (*meta_generator)[index] = MakeMetaGen( + (*meta_generator)[index].GetForm(), + (*meta_generator)[index].GetCounter()+1, + ) return (*meta_generator)[index].GetForm() } else { index_less_reintroduced_meta := chooseLessReintroducedMeta(*meta_generator, nil) @@ -184,7 +191,10 @@ func ReintroduceMetaIfLessReintroduced(meta_generator *[]MetaGen, index int) For } else { index_less_reintroduced_meta = indexes_less_reintroduced_meta[0] } - (*meta_generator)[index_less_reintroduced_meta] = MakeMetaGen((*meta_generator)[index_less_reintroduced_meta].GetForm(), (*meta_generator)[index_less_reintroduced_meta].GetCounter()+1) + (*meta_generator)[index_less_reintroduced_meta] = MakeMetaGen( + (*meta_generator)[index_less_reintroduced_meta].GetForm(), + (*meta_generator)[index_less_reintroduced_meta].GetCounter()+1, + ) return (*meta_generator)[index_less_reintroduced_meta].GetForm() } diff --git a/src/Core/subst_and_form.go b/src/Core/subst_and_form.go index 92629c59..ae6eb6e9 100644 --- a/src/Core/subst_and_form.go +++ b/src/Core/subst_and_form.go @@ -198,7 +198,14 @@ func MergeSubstAndForm(s1, s2 SubstAndForm) (error, SubstAndForm) { new_subst, _ := Unif.MergeSubstitutions(s1.GetSubst().Copy(), s2.GetSubst().Copy()) if new_subst.Equals(Unif.Failure()) { - Glob.PrintError("MSAF", fmt.Sprintf("Error : MergeSubstitutions returns failure between : %v and %v \n", s1.ToString(), s2.ToString())) + Glob.PrintError( + "MSAF", + fmt.Sprintf( + "Error : MergeSubstitutions returns failure between : %v and %v \n", + s1.ToString(), + s2.ToString(), + ), + ) return errors.New("Couldn't merge two substitutions"), MakeEmptySubstAndForm() } diff --git a/src/Core/subst_and_form_and_terms.go b/src/Core/subst_and_form_and_terms.go index 0b72fe73..ec0e4619 100644 --- a/src/Core/subst_and_form_and_terms.go +++ b/src/Core/subst_and_form_and_terms.go @@ -92,7 +92,10 @@ func (s SubstAndFormAndTerms) ToString() string { return res } -func MakeSubstAndFormAndTerms(subst Unif.Substitutions, form FormAndTermsList) SubstAndFormAndTerms { +func MakeSubstAndFormAndTerms( + subst Unif.Substitutions, + form FormAndTermsList, +) SubstAndFormAndTerms { return SubstAndFormAndTerms{subst.Copy(), form.Copy()} } func MakeEmptySubstAndFormAndTerms() SubstAndFormAndTerms { @@ -110,7 +113,10 @@ func ContainsSubstAndFormAndTerms(s SubstAndFormAndTerms, sl []SubstAndFormAndTe } /* Append a substitution s to a list of substitution sl if s is not in sl */ -func AppendIfNotContainsSubstAndFormAndTerms(sl []SubstAndFormAndTerms, s SubstAndFormAndTerms) []SubstAndFormAndTerms { +func AppendIfNotContainsSubstAndFormAndTerms( + sl []SubstAndFormAndTerms, + s SubstAndFormAndTerms, +) []SubstAndFormAndTerms { if !ContainsSubstAndFormAndTerms(s, sl) { return append(sl, s) } else { diff --git a/src/Core/substitutions_search.go b/src/Core/substitutions_search.go index 51403ed8..46ed3408 100644 --- a/src/Core/substitutions_search.go +++ b/src/Core/substitutions_search.go @@ -117,7 +117,9 @@ func RemoveElementWithoutMM(subs Unif.Substitutions, mm Lib.Set[AST.Meta]) Unif. } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Subst intermédiaire res : %v", res.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Subst intermédiaire res : %v", res.ToString()) }, + ), ) debug( Lib.MkLazy(func() string { @@ -144,10 +146,13 @@ func RemoveElementWithoutMM(subs Unif.Substitutions, mm Lib.Set[AST.Meta]) Unif. } -/* * +/* + * + * Take a substitution wich conatins elements like (meta_mother, meta_current), returning only relevante substitution like (meta_mother, meta_mother) * (X, X2) (Y, X2) -> (X, Y) -**/ +* +*/ func ReorganizeSubstitution(subs Unif.Substitutions) Unif.Substitutions { res := Unif.Substitutions{} metaSeen := Lib.NewList[AST.Meta]() @@ -269,10 +274,18 @@ func ApplySubstitutionOnTermList( return res } -func applySubstitutionOnTypeList(old_symbol AST.Meta, new_symbol AST.Term, tl []AST.TypeApp) []AST.TypeApp { +func applySubstitutionOnTypeList( + old_symbol AST.Meta, + new_symbol AST.Term, + tl []AST.TypeApp, +) []AST.TypeApp { res := make([]AST.TypeApp, len(tl)) for i, t := range tl { - res[i] = applySubstitutionOnType(old_symbol.GetTypeApp(), new_symbol.(AST.TypedTerm).GetTypeApp(), t) + res[i] = applySubstitutionOnType( + old_symbol.GetTypeApp(), + new_symbol.(AST.TypedTerm).GetTypeApp(), + t, + ) } return res } @@ -358,7 +371,10 @@ func ApplySubstitutionsOnFormAndTerms(s Unif.Substitutions, fat FormAndTerms) Fo } /* For each element of the substitution, apply it on the entire formAndTerms list */ -func ApplySubstitutionsOnFormAndTermsList(s Unif.Substitutions, lf FormAndTermsList) FormAndTermsList { +func ApplySubstitutionsOnFormAndTermsList( + s Unif.Substitutions, + lf FormAndTermsList, +) FormAndTermsList { lf_res := MakeEmptyFormAndTermsList() for _, f := range lf { new_form := ApplySubstitutionsOnFormAndTerms(s, f) @@ -393,7 +409,10 @@ func ApplySubstitutionOnMetaGen(s Unif.Substitutions, mg MetaGen) MetaGen { } /* Dispatch a list of substitution : containing mm or not */ -func DispatchSubst(subsList []Unif.Substitutions, mm Lib.Set[AST.Meta]) ([]Unif.Substitutions, []Unif.Substitutions, []Unif.Substitutions) { +func DispatchSubst( + subsList []Unif.Substitutions, + mm Lib.Set[AST.Meta], +) ([]Unif.Substitutions, []Unif.Substitutions, []Unif.Substitutions) { var subsWithMM []Unif.Substitutions var subsWithMMUncleared []Unif.Substitutions var subsWithoutMM []Unif.Substitutions @@ -434,7 +453,8 @@ func AreEqualsModuloaLaphaConversion(s1, s2 Unif.Substitutions) bool { i := 0 for i < len(s1) && cpt == i { for _, s2_element := range s2 { - if (s1[i].Key().GetName() == s2_element.Key().GetName()) && (s1[i].Value().Equals(s2_element.Value())) { + if (s1[i].Key().GetName() == s2_element.Key().GetName()) && + (s1[i].Value().Equals(s2_element.Value())) { cpt++ } } diff --git a/src/Engine/pretyper.go b/src/Engine/pretyper.go index 1b077b51..35a9c45e 100644 --- a/src/Engine/pretyper.go +++ b/src/Engine/pretyper.go @@ -38,6 +38,7 @@ package Engine import ( "fmt" + "github.com/GoelandProver/Goeland/AST" "github.com/GoelandProver/Goeland/Glob" "github.com/GoelandProver/Goeland/Lib" diff --git a/src/Engine/syntax-translation.go b/src/Engine/syntax-translation.go index 8efed527..e613a1a5 100644 --- a/src/Engine/syntax-translation.go +++ b/src/Engine/syntax-translation.go @@ -38,6 +38,7 @@ package Engine import ( "fmt" + "github.com/GoelandProver/Goeland/AST" "github.com/GoelandProver/Goeland/Core" "github.com/GoelandProver/Goeland/Glob" diff --git a/src/Glob/helper.go b/src/Glob/helper.go index 979e9ed4..a8fe34fd 100644 --- a/src/Glob/helper.go +++ b/src/Glob/helper.go @@ -39,13 +39,14 @@ package Glob import ( "bytes" "fmt" - "github.com/GoelandProver/Goeland/Lib" "os" "runtime" "strconv" "strings" "sync" "time" + + "github.com/GoelandProver/Goeland/Lib" ) var orocq = false diff --git a/src/Glob/log.go b/src/Glob/log.go index 91543837..ac1c1fe8 100644 --- a/src/Glob/log.go +++ b/src/Glob/log.go @@ -37,13 +37,14 @@ package Glob import ( "fmt" - "github.com/GoelandProver/Goeland/Lib" "io" "log" "os" "path/filepath" "runtime" "time" + + "github.com/GoelandProver/Goeland/Lib" ) var ( @@ -136,7 +137,11 @@ func EnableWriteLogs() { wrt = io.MultiWriter(os.Stdout, f) - f, err = os.OpenFile("/tmp/Goeland"+time.Now().Format("[2006-01-02 15:04:05]")+".log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666) + f, err = os.OpenFile( + "/tmp/Goeland"+time.Now().Format("[2006-01-02 15:04:05]")+".log", + os.O_RDWR|os.O_CREATE|os.O_TRUNC, + 0666, + ) if err != nil { log.Fatalf("Error opening log file: %v", err) diff --git a/src/Glob/pair.go b/src/Glob/pair.go index 663d92e2..ff635d61 100644 --- a/src/Glob/pair.go +++ b/src/Glob/pair.go @@ -95,7 +95,8 @@ func NewUnorderedBasicPair[T Basic](fst T, snd T) *UnorderedBasicPair[T] { func (ubp *UnorderedBasicPair[T]) Equals(other any) bool { if typed, ok := other.(*UnorderedBasicPair[T]); ok { - return (ubp.fst.Equals(typed.fst) && ubp.snd.Equals(typed.snd)) || (ubp.fst.Equals(typed.snd) && ubp.snd.Equals(typed.fst)) + return (ubp.fst.Equals(typed.fst) && ubp.snd.Equals(typed.snd)) || + (ubp.fst.Equals(typed.snd) && ubp.snd.Equals(typed.fst)) } return false diff --git a/src/Mods/assisted/assistant.go b/src/Mods/assisted/assistant.go index 1064567e..a2e1d068 100644 --- a/src/Mods/assisted/assistant.go +++ b/src/Mods/assisted/assistant.go @@ -178,7 +178,10 @@ func selectStatus() int { } } - fmt.Printf("\nState nº%d is not in the list. Please select a valid state ID.\n", chosenStatus) + fmt.Printf( + "\nState nº%d is not in the list. Please select a valid state ID.\n", + chosenStatus, + ) } } diff --git a/src/Mods/assisted/rules.go b/src/Mods/assisted/rules.go index 9e288dc6..475b0fbd 100644 --- a/src/Mods/assisted/rules.go +++ b/src/Mods/assisted/rules.go @@ -42,7 +42,15 @@ import ( "github.com/GoelandProver/Goeland/Unif" ) -func ApplyRulesAssisted(fatherId uint64, state Search.State, c Search.Communication, newAtomics Core.FormAndTermsList, nodeID int, originalNodeId int, metaToReintroduce []int) { +func ApplyRulesAssisted( + fatherId uint64, + state Search.State, + c Search.Communication, + newAtomics Core.FormAndTermsList, + nodeID int, + originalNodeId int, + metaToReintroduce []int, +) { ch := make(chan Choice) @@ -56,32 +64,76 @@ func ApplyRulesAssisted(fatherId uint64, state Search.State, c Search.Communicat switch chosenRule { case "X": - applyAtomicRule(state, fatherId, c, nodeID, originalNodeId, chosenSubstitute, metaToReintroduce) + applyAtomicRule( + state, + fatherId, + c, + nodeID, + originalNodeId, + chosenSubstitute, + metaToReintroduce, + ) case "A": applyAlphaRule(state, chosenFormIndex, fatherId, c, chosenSubstitute, originalNodeId) case "B": - applyBetaRule(state, chosenSubstitute, c, fatherId, nodeID, originalNodeId, metaToReintroduce) + applyBetaRule( + state, + chosenSubstitute, + c, + fatherId, + nodeID, + originalNodeId, + metaToReintroduce, + ) case "D": applyDeltaRule(state, chosenFormIndex, fatherId, c, chosenSubstitute, originalNodeId) case "G": applyGammaRule(state, chosenFormIndex, fatherId, c, chosenSubstitute, originalNodeId) case "R": - applyReintroductionRule(state, fatherId, c, originalNodeId, metaToReintroduce, chosenReintro) + applyReintroductionRule( + state, + fatherId, + c, + originalNodeId, + metaToReintroduce, + chosenReintro, + ) } } -func applyAtomicRule(state Search.State, fatherId uint64, c Search.Communication, nodeId int, originalNodeId int, substitut Core.SubstAndForm, metaToReintroduce []int) { +func applyAtomicRule( + state Search.State, + fatherId uint64, + c Search.Communication, + nodeId int, + originalNodeId int, + substitut Core.SubstAndForm, + metaToReintroduce []int, +) { foundOne := false listSubsts := [][]Core.SubstAndForm{} finalBool := true for _, f := range state.GetAtomic() { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("##### Formula %v #####", f.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("##### Formula %v #####", f.ToString()) }, + ), ) - clos_res_after_apply_subst, subst_after_apply_subst := Search.ApplyClosureRules(f.GetForm(), &state) + clos_res_after_apply_subst, subst_after_apply_subst := Search.ApplyClosureRules( + f.GetForm(), + &state, + ) if clos_res_after_apply_subst { - boolSubsts, resSubsts := searchAlgo.ManageClosureRule(fatherId, &state, c, Unif.CopySubstList(subst_after_apply_subst), f.Copy(), nodeId, originalNodeId) + boolSubsts, resSubsts := searchAlgo.ManageClosureRule( + fatherId, + &state, + c, + Unif.CopySubstList(subst_after_apply_subst), + f.Copy(), + nodeId, + originalNodeId, + ) if !boolSubsts { finalBool = false } @@ -97,7 +149,16 @@ func applyAtomicRule(state Search.State, fatherId uint64, c Search.Communication }), ) assistedCounter.Increment() - go searchAlgo.ProofSearch(fatherId, state, c, substitut, nodeId, originalNodeId, metaToReintroduce, false) + go searchAlgo.ProofSearch( + fatherId, + state, + c, + substitut, + nodeId, + originalNodeId, + metaToReintroduce, + false, + ) } else { listSubsts2 := []Core.SubstAndForm{} for _, elem := range listSubsts { @@ -117,7 +178,14 @@ func applyAtomicRule(state Search.State, fatherId uint64, c Search.Communication } } -func applyAlphaRule(state Search.State, indiceForm int, fatherId uint64, c Search.Communication, substitut Core.SubstAndForm, originalNodeId int) { +func applyAlphaRule( + state Search.State, + indiceForm int, + fatherId uint64, + c Search.Communication, + substitut Core.SubstAndForm, + originalNodeId int, +) { debug(Lib.MkLazy(func() string { return "User chose Alpha rule" })) hdf := state.GetAlpha()[indiceForm] debug( @@ -130,14 +198,33 @@ func applyAlphaRule(state Search.State, indiceForm int, fatherId uint64, c Searc state.SetCurrentProofFormula(hdf) id_children := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(id_children, result_forms)}) + state.SetCurrentProofResultFormulas( + []Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(id_children, result_forms)}, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) assistedCounter.Increment() - go searchAlgo.ProofSearch(fatherId, state, c, substitut, id_children, originalNodeId, []int{}, false) + go searchAlgo.ProofSearch( + fatherId, + state, + c, + substitut, + id_children, + originalNodeId, + []int{}, + false, + ) } -func applyBetaRule(state Search.State, substitut Core.SubstAndForm, c Search.Communication, fatherId uint64, nodeId int, originalNodeId int, metaToReintroduce []int) { +func applyBetaRule( + state Search.State, + substitut Core.SubstAndForm, + c Search.Communication, + fatherId uint64, + nodeId int, + originalNodeId int, + metaToReintroduce []int, +) { debug(Lib.MkLazy(func() string { return "User chose Beta rule" })) hdf := state.GetBeta()[0] debug(Lib.MkLazy(func() string { return fmt.Sprintf("Rule applied on : %s", hdf.ToString()) })) @@ -148,7 +235,10 @@ func applyBetaRule(state Search.State, substitut Core.SubstAndForm, c Search.Com int_form_list_list := []Search.IntFormAndTermsList{} for _, fl := range reslf { - int_form_list_list = append(int_form_list_list, Search.MakeIntFormAndTermsList(Glob.IncrCptNode(), fl)) + int_form_list_list = append( + int_form_list_list, + Search.MakeIntFormAndTermsList(Glob.IncrCptNode(), fl), + ) } state.SetCurrentProofResultFormulas(int_form_list_list) state.SetBTOnFormulas(false) @@ -168,7 +258,16 @@ func applyBetaRule(state Search.State, substitut Core.SubstAndForm, c Search.Com if Glob.IsDestructive() { c_child := Search.MakeCommunication(make(chan bool), make(chan Search.Result)) chan_tab = append(chan_tab, c_child) - go searchAlgo.ProofSearch(Glob.GetGID(), st_copy, c_child, substitut, fl.GetI(), fl.GetI(), []int{}, false) + go searchAlgo.ProofSearch( + Glob.GetGID(), + st_copy, + c_child, + substitut, + fl.GetI(), + fl.GetI(), + []int{}, + false, + ) } else { go searchAlgo.ProofSearch(Glob.GetGID(), st_copy, c, substitut, fl.GetI(), fl.GetI(), []int{}, false) } @@ -178,10 +277,26 @@ func applyBetaRule(state Search.State, substitut Core.SubstAndForm, c Search.Com } - searchAlgo.DoEndManageBeta(fatherId, state, c, chan_tab, nodeId, originalNodeId, child_id_list, metaToReintroduce) + searchAlgo.DoEndManageBeta( + fatherId, + state, + c, + chan_tab, + nodeId, + originalNodeId, + child_id_list, + metaToReintroduce, + ) } -func applyDeltaRule(state Search.State, indiceForm int, fatherId uint64, c Search.Communication, substitut Core.SubstAndForm, originalNodeId int) { +func applyDeltaRule( + state Search.State, + indiceForm int, + fatherId uint64, + c Search.Communication, + substitut Core.SubstAndForm, + originalNodeId int, +) { debug(Lib.MkLazy(func() string { return "User chose Delta rule" })) hdf := state.GetDelta()[indiceForm] debug( @@ -194,14 +309,32 @@ func applyDeltaRule(state Search.State, indiceForm int, fatherId uint64, c Searc state.SetCurrentProofFormula(hdf) id_children := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(id_children, result_forms)}) + state.SetCurrentProofResultFormulas( + []Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(id_children, result_forms)}, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) assistedCounter.Increment() - go searchAlgo.ProofSearch(fatherId, state, c, substitut, id_children, originalNodeId, []int{}, false) + go searchAlgo.ProofSearch( + fatherId, + state, + c, + substitut, + id_children, + originalNodeId, + []int{}, + false, + ) } -func applyGammaRule(state Search.State, indiceForm int, fatherId uint64, c Search.Communication, substitut Core.SubstAndForm, originalNodeId int) { +func applyGammaRule( + state Search.State, + indiceForm int, + fatherId uint64, + c Search.Communication, + substitut Core.SubstAndForm, + originalNodeId int, +) { debug( Lib.MkLazy(func() string { return "User chose Gamma rule" }), ) @@ -226,14 +359,32 @@ func applyGammaRule(state Search.State, indiceForm int, fatherId uint64, c Searc state.SetCurrentProofFormula(hdf) id_children := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(id_children, new_lf)}) + state.SetCurrentProofResultFormulas( + []Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(id_children, new_lf)}, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) assistedCounter.Decrement() - go searchAlgo.ProofSearch(fatherId, state, c, substitut, id_children, originalNodeId, []int{}, false) + go searchAlgo.ProofSearch( + fatherId, + state, + c, + substitut, + id_children, + originalNodeId, + []int{}, + false, + ) } -func applyReintroductionRule(state Search.State, fatherId uint64, c Search.Communication, originalNodeId int, metaToReintroduce []int, chosenReintro int) { +func applyReintroductionRule( + state Search.State, + fatherId uint64, + c Search.Communication, + originalNodeId int, + metaToReintroduce []int, + chosenReintro int, +) { debug(Lib.MkLazy(func() string { return "Reintroduction" })) debug( Lib.MkLazy(func() string { @@ -245,7 +396,9 @@ func applyReintroductionRule(state Search.State, fatherId uint64, c Search.Commu newMetaGen := state.GetMetaGen() reslf := Core.ReintroduceMeta(&newMetaGen, chosenReintro, state.GetN()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Reintroduce the formula : %s", reslf.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Reintroduce the formula : %s", reslf.ToString()) }, + ), ) state.SetLF(Core.MakeSingleElementFormAndTermList(reslf)) @@ -255,9 +408,22 @@ func applyReintroductionRule(state Search.State, fatherId uint64, c Search.Commu state.SetCurrentProofRule("Reintroduction") state.SetCurrentProofRuleName("Reintroduction") state.SetCurrentProofFormula(reslf) - state.SetCurrentProofResultFormulas([]Search.IntFormAndTermsList{Search.MakeIntFormAndTermsList(childId, Core.MakeSingleElementFormAndTermList(reslf))}) + state.SetCurrentProofResultFormulas( + []Search.IntFormAndTermsList{ + Search.MakeIntFormAndTermsList(childId, Core.MakeSingleElementFormAndTermList(reslf)), + }, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) assistedCounter.Increment() - go searchAlgo.ProofSearch(fatherId, state, c, Core.MakeEmptySubstAndForm(), childId, originalNodeId, metaToReintroduce, false) + go searchAlgo.ProofSearch( + fatherId, + state, + c, + Core.MakeEmptySubstAndForm(), + childId, + originalNodeId, + metaToReintroduce, + false, + ) } diff --git a/src/Mods/assisted/status.go b/src/Mods/assisted/status.go index e5a92b96..2cc52cc7 100644 --- a/src/Mods/assisted/status.go +++ b/src/Mods/assisted/status.go @@ -97,7 +97,9 @@ func (se *StatusElement) applySubs(sub Core.SubstAndForm) { func (se *StatusElement) sendChoice(choice Choice) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Choice sent to state nº%d : %v", se.getId(), choice) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Choice sent to state nº%d : %v", se.getId(), choice) }, + ), ) se.channel <- choice @@ -106,7 +108,9 @@ func (se *StatusElement) sendChoice(choice Choice) { func (se *StatusElement) receiveChoice() Choice { choice := <-se.channel debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Choice received from state nº%d : %v", se.getId(), choice) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Choice received from state nº%d : %v", se.getId(), choice) }, + ), ) return choice } diff --git a/src/Mods/dmt/dmt.go b/src/Mods/dmt/dmt.go index e4cf0351..01d2f58c 100644 --- a/src/Mods/dmt/dmt.go +++ b/src/Mods/dmt/dmt.go @@ -115,7 +115,6 @@ func parsePluginOptions() { Glob.PrintInfo("DMT", output) } - func GetRegisteredAxioms() *AST.FormList { return registeredAxioms } diff --git a/src/Mods/dmt/rewrite.go b/src/Mods/dmt/rewrite.go index 2fdbbac6..05c4362c 100644 --- a/src/Mods/dmt/rewrite.go +++ b/src/Mods/dmt/rewrite.go @@ -55,7 +55,12 @@ func Rewrite(atomic AST.Form) ([]Core.IntSubstAndForm, error) { return rewriteGeneric(tree, atomic, form, polarity) } -func rewriteGeneric(tree Unif.DataStructure, atomic AST.Form, form AST.Form, polarity bool) ([]Core.IntSubstAndForm, error) { +func rewriteGeneric( + tree Unif.DataStructure, + atomic AST.Form, + form AST.Form, + polarity bool, +) ([]Core.IntSubstAndForm, error) { rewritten := []Core.IntSubstAndForm{} var err error = nil @@ -67,7 +72,12 @@ func rewriteGeneric(tree Unif.DataStructure, atomic AST.Form, form AST.Form, pol return rewritten, err } -func getRewrittenFormulas(rewritten []Core.IntSubstAndForm, unif []Unif.MatchingSubstitutions, atomic AST.Form, polarity bool) ([]Core.IntSubstAndForm, error) { +func getRewrittenFormulas( + rewritten []Core.IntSubstAndForm, + unif []Unif.MatchingSubstitutions, + atomic AST.Form, + polarity bool, +) ([]Core.IntSubstAndForm, error) { unifs := sortUnifications(unif, polarity, atomic) if len(unifs) == 0 { rewritten = rewriteFailure(atomic) @@ -84,12 +94,25 @@ func getRewrittenFormulas(rewritten []Core.IntSubstAndForm, unif []Unif.Matching return rewritten, nil } -func addRewrittenFormulas(rewritten []Core.IntSubstAndForm, unif Unif.MatchingSubstitutions, atomic AST.Form, equivalence *AST.FormList) []Core.IntSubstAndForm { +func addRewrittenFormulas( + rewritten []Core.IntSubstAndForm, + unif Unif.MatchingSubstitutions, + atomic AST.Form, + equivalence *AST.FormList, +) []Core.IntSubstAndForm { // Keep only useful substitutions useful_subst := Core.RemoveElementWithoutMM(unif.GetSubst(), atomic.GetMetas()) meta_search := atomic.GetMetas() if !checkMetaAreFromSearch(meta_search, useful_subst) { - Glob.PrintError("DMT", fmt.Sprintf("There is at least one meta in final subst which is not from search : %v - %v - %v", useful_subst.ToString(), atomic.ToString(), unif.GetForm().ToString())) + Glob.PrintError( + "DMT", + fmt.Sprintf( + "There is at least one meta in final subst which is not from search : %v - %v - %v", + useful_subst.ToString(), + atomic.ToString(), + unif.GetForm().ToString(), + ), + ) } filteredUnif := Unif.MakeMatchingSubstitutions( unif.GetForm(), @@ -121,14 +144,24 @@ func getAtomAndPolarity(atom AST.Form) (AST.Form, bool) { func rewriteFailure(atomic AST.Form) []Core.IntSubstAndForm { return []Core.IntSubstAndForm{ - Core.MakeIntSubstAndForm(-1, Core.MakeSubstAndForm(Unif.Failure(), AST.NewFormList(atomic))), + Core.MakeIntSubstAndForm( + -1, + Core.MakeSubstAndForm(Unif.Failure(), AST.NewFormList(atomic)), + ), } } -func addUnifToAtomics(atomics []Core.IntSubstAndForm, candidate AST.Form, unif Unif.MatchingSubstitutions) []Core.IntSubstAndForm { +func addUnifToAtomics( + atomics []Core.IntSubstAndForm, + candidate AST.Form, + unif Unif.MatchingSubstitutions, +) []Core.IntSubstAndForm { substAndForm := Core.MakeSubstAndForm(unif.GetSubst().Copy(), AST.NewFormList(candidate)) if isBotOrTop(candidate) { - atomics = Core.InsertFirstIntSubstAndFormList(atomics, Core.MakeIntSubstAndForm(unif.GetForm().GetIndex(), substAndForm)) + atomics = Core.InsertFirstIntSubstAndFormList( + atomics, + Core.MakeIntSubstAndForm(unif.GetForm().GetIndex(), substAndForm), + ) } else { atomics = append(atomics, Core.MakeIntSubstAndForm(unif.GetForm().GetIndex(), substAndForm)) } @@ -139,7 +172,11 @@ func isBotOrTop(form AST.Form) bool { return Glob.Is[AST.Bot](form) || Glob.Is[AST.Top](form) } -func sortUnifications(unifs []Unif.MatchingSubstitutions, polarity bool, atomic AST.Form) []Unif.MatchingSubstitutions { +func sortUnifications( + unifs []Unif.MatchingSubstitutions, + polarity bool, + atomic AST.Form, +) []Unif.MatchingSubstitutions { rewriteMap := selectFromPolarity(polarity, positiveRewrite, negativeRewrite) sortedUnifs := []Unif.MatchingSubstitutions{} @@ -155,7 +192,11 @@ func sortUnifications(unifs []Unif.MatchingSubstitutions, polarity bool, atomic } // Priority of substitutions: Top/Bottom > others -func insert(sortedUnifs []Unif.MatchingSubstitutions, list *AST.FormList, unif Unif.MatchingSubstitutions) []Unif.MatchingSubstitutions { +func insert( + sortedUnifs []Unif.MatchingSubstitutions, + list *AST.FormList, + unif Unif.MatchingSubstitutions, +) []Unif.MatchingSubstitutions { if list.Contains(AST.MakerTop()) || list.Contains(AST.MakerBot()) { sortedUnifs = insertFirst(sortedUnifs, unif) } else { @@ -164,7 +205,10 @@ func insert(sortedUnifs []Unif.MatchingSubstitutions, list *AST.FormList, unif U return sortedUnifs } -func insertFirst(sortedUnifs []Unif.MatchingSubstitutions, unif Unif.MatchingSubstitutions) []Unif.MatchingSubstitutions { +func insertFirst( + sortedUnifs []Unif.MatchingSubstitutions, + unif Unif.MatchingSubstitutions, +) []Unif.MatchingSubstitutions { if len(sortedUnifs) > 0 { // Moves everything to the right once. sortedUnifs = append(sortedUnifs[:1], sortedUnifs[0:]...) @@ -213,10 +257,17 @@ func checkMetaAreFromSearch(metas Lib.Set[AST.Meta], subst Unif.Substitutions) b return true } -func getUnifiedEquivalence(atom AST.Form, subst Unif.Substitutions, polarity bool) (*AST.FormList, error) { +func getUnifiedEquivalence( + atom AST.Form, + subst Unif.Substitutions, + polarity bool, +) (*AST.FormList, error) { equivalence := findEquivalence(atom, polarity) if equivalence == nil { - return nil, fmt.Errorf("[DMT] Fatal error : no rewrite rule found when an unification has been found : %v", atom.ToString()) + return nil, fmt.Errorf( + "[DMT] Fatal error : no rewrite rule found when an unification has been found : %v", + atom.ToString(), + ) } res := AST.NewFormList() diff --git a/src/Mods/equality/bse/constraints_list.go b/src/Mods/equality/bse/constraints_list.go index 203f66d9..32a20aa7 100644 --- a/src/Mods/equality/bse/constraints_list.go +++ b/src/Mods/equality/bse/constraints_list.go @@ -89,7 +89,9 @@ func makeEmptyConstaintsList() ConstraintList { /* Check if a constraint is consistant with LPO and constraint list */ func (cl ConstraintList) isConsistantWithSubst(s Unif.Substitutions) bool { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Is consistant with the subst : %v", s.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Is consistant with the subst : %v", s.ToString()) }, + ), ) for _, c_element := range cl { c := c_element.copy() @@ -98,7 +100,9 @@ func (cl ConstraintList) isConsistantWithSubst(s Unif.Substitutions) bool { ) c.applySubstitution(s) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Constraint after apply subst : %v", c.toString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Constraint after apply subst : %v", c.toString()) }, + ), ) respect_lpo, is_comparable := c.checkLPO() debug( @@ -128,17 +132,41 @@ func (cl ConstraintList) checkConstraintList() bool { debug(Lib.MkLazy(func() string { return fmt.Sprintf("Constraint : %v", c.toString()) })) switch c.getCType() { case PREC: - if !appendToMapAndCheck(c.getTP().GetT1().ToString(), c.getTP().GetT2(), &map_constraintes, 1, 2) { + if !appendToMapAndCheck( + c.getTP().GetT1().ToString(), + c.getTP().GetT2(), + &map_constraintes, + 1, + 2, + ) { return false } - if !appendToMapAndCheck(c.getTP().GetT2().ToString(), c.getTP().GetT1(), &map_constraintes, 2, 2) { + if !appendToMapAndCheck( + c.getTP().GetT2().ToString(), + c.getTP().GetT1(), + &map_constraintes, + 2, + 2, + ) { return false } case EQ: - if !appendToMapAndCheck(c.getTP().GetT1().ToString(), c.getTP().GetT2(), &map_constraintes, 0, 2) { + if !appendToMapAndCheck( + c.getTP().GetT1().ToString(), + c.getTP().GetT2(), + &map_constraintes, + 0, + 2, + ) { return false } - if !appendToMapAndCheck(c.getTP().GetT2().ToString(), c.getTP().GetT1(), &map_constraintes, 0, 2) { + if !appendToMapAndCheck( + c.getTP().GetT2().ToString(), + c.getTP().GetT1(), + &map_constraintes, + 0, + 2, + ) { return false } } diff --git a/src/Mods/equality/bse/constraints_struct.go b/src/Mods/equality/bse/constraints_struct.go index dc5c79e9..dbd039bf 100644 --- a/src/Mods/equality/bse/constraints_struct.go +++ b/src/Mods/equality/bse/constraints_struct.go @@ -77,12 +77,26 @@ func (cs ConstraintStruct) copy() ConstraintStruct { return makeConstraintStruct(cs.getAllConstraints(), cs.getSubst(), cs.getPrec()) } func (cs ConstraintStruct) toString() string { - return "EQ subst : " + cs.getSubst().ToString() + " - PREC List : " + cs.getPrec().toString() + " - All cst : " + cs.getAllConstraints().toString() + return "EQ subst : " + cs.getSubst(). + ToString() + + " - PREC List : " + cs.getPrec(). + toString() + + " - All cst : " + cs.getAllConstraints(). + toString() } func makeEmptyConstraintStruct() ConstraintStruct { - return ConstraintStruct{makeEmptyConstaintsList(), Unif.MakeEmptySubstitution(), makeEmptyConstaintsList()} + return ConstraintStruct{ + makeEmptyConstaintsList(), + Unif.MakeEmptySubstitution(), + makeEmptyConstaintsList(), + } } -func makeConstraintStruct(ac ConstraintList, s Unif.Substitutions, p ConstraintList) ConstraintStruct { + +func makeConstraintStruct( + ac ConstraintList, + s Unif.Substitutions, + p ConstraintList, +) ConstraintStruct { res := makeEmptyConstraintStruct() res.setAllConstraits(ac) res.setSubst(s) @@ -98,7 +112,9 @@ func (cs *ConstraintStruct) appendIfConsistant(c Constraint) bool { Lib.MkLazy(func() string { return fmt.Sprintf("%v is consistant", c.toString()) }), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("CL at the end : %v", cs.toString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("CL at the end : %v", cs.toString()) }, + ), ) return true } else { @@ -147,9 +163,15 @@ func (cs *ConstraintStruct) isConsistantWith(c Constraint) bool { case EQ: // Check if the EQ constraint is unifiable - subst := Unif.AddUnification(c.getTP().GetT1().Copy(), c.getTP().GetT2().Copy(), Unif.MakeEmptySubstitution()) + subst := Unif.AddUnification( + c.getTP().GetT1().Copy(), + c.getTP().GetT2().Copy(), + Unif.MakeEmptySubstitution(), + ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Candidate subst : %v", subst.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Candidate subst : %v", subst.ToString()) }, + ), ) if subst.Equals(Unif.Failure()) { return false @@ -178,7 +200,9 @@ func (cs *ConstraintStruct) isConsistantWith(c Constraint) bool { // Add it to subst and check unification consistency subst_all := Unif.AddUnification(c.getTP().GetT1(), c.getTP().GetT2(), cs.getSubst()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Subst all : %v", subst_all.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Subst all : %v", subst_all.ToString()) }, + ), ) if subst_all.Equals(Unif.Failure()) { return false diff --git a/src/Mods/equality/bse/constraints_type.go b/src/Mods/equality/bse/constraints_type.go index f63692bc..09aecb7c 100644 --- a/src/Mods/equality/bse/constraints_type.go +++ b/src/Mods/equality/bse/constraints_type.go @@ -100,11 +100,15 @@ func (c *Constraint) applySubstitution(s Unif.Substitutions) { /* return true if the constraint is not violated, false otherwise + true is the contraint is comparable, false otherwise + update c into the useful part of the constraint */ func (c *Constraint) checkLPO() (bool, bool) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Type %v, cst : %v", c.getCType(), c.toString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Type %v, cst : %v", c.getCType(), c.toString()) }, + ), ) cs := compareLPO(c.getTP().GetT1(), c.getTP().GetT2()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("res : %v, is_comparable : %v", cs.order, cs.is_comparable) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("res : %v, is_comparable : %v", cs.order, cs.is_comparable) }, + ), ) if cs.is_comparable { diff --git a/src/Mods/equality/bse/equality.go b/src/Mods/equality/bse/equality.go index ee12afae..214d7745 100644 --- a/src/Mods/equality/bse/equality.go +++ b/src/Mods/equality/bse/equality.go @@ -61,13 +61,27 @@ func SetTryEquality() { Search.TryEquality = TryEquality } -func TryEquality(atomics_for_dmt Core.FormAndTermsList, st Search.State, new_atomics Core.FormAndTermsList, father_id uint64, cha Search.Communication, node_id int, original_node_id int) bool { +func TryEquality( + atomics_for_dmt Core.FormAndTermsList, + st Search.State, + new_atomics Core.FormAndTermsList, + father_id uint64, + cha Search.Communication, + node_id int, + original_node_id int, +) bool { if !Glob.GetDMTBeforeEq() || len(atomics_for_dmt) == 0 || len(st.GetLF()) == 0 { debug(Lib.MkLazy(func() string { return "Try apply EQ !" })) if len(new_atomics) > 0 || len(st.GetLF()) == 0 { debug(Lib.MkLazy(func() string { return "EQ is applicable !" })) atomics_plus_dmt := append(st.GetAtomic(), atomics_for_dmt...) - res_eq, subst_eq := EqualityReasoning(st.GetEqStruct(), st.GetTreePos(), st.GetTreeNeg(), atomics_plus_dmt.ExtractForms(), original_node_id) + res_eq, subst_eq := EqualityReasoning( + st.GetEqStruct(), + st.GetTreePos(), + st.GetTreeNeg(), + atomics_plus_dmt.ExtractForms(), + original_node_id, + ) if res_eq { Search.UsedSearch.ManageClosureRule( father_id, @@ -94,7 +108,12 @@ func TryEquality(atomics_for_dmt Core.FormAndTermsList, st Search.State, new_ato * creates the problem * returns a bool for success and the corresponding substitution **/ -func EqualityReasoning(eqStruct eqStruct.EqualityStruct, tree_pos, tree_neg Unif.DataStructure, atomic *AST.FormList, originalNodeId int) (bool, []Unif.Substitutions) { +func EqualityReasoning( + eqStruct eqStruct.EqualityStruct, + tree_pos, tree_neg Unif.DataStructure, + atomic *AST.FormList, + originalNodeId int, +) (bool, []Unif.Substitutions) { debug(Lib.MkLazy(func() string { return "ER call" })) problem, equalities := buildEqualityProblemMultiList(atomic, tree_pos, tree_neg) if equalities { diff --git a/src/Mods/equality/bse/equality_problem.go b/src/Mods/equality/bse/equality_problem.go index b2e4ad91..8fcd4444 100644 --- a/src/Mods/equality/bse/equality_problem.go +++ b/src/Mods/equality/bse/equality_problem.go @@ -77,7 +77,14 @@ func (ep EqualityProblem) copy() EqualityProblem { return makeEqualityProblem(ep.GetE(), ep.GetS(), ep.GetT(), ep.getC()) } func (ep EqualityProblem) ToString() string { - return "<" + ep.GetE().ToString() + ", " + ep.GetS().ToString() + ", " + ep.GetT().ToString() + "> • " + ep.getC().toString() + return "<" + ep.GetE(). + ToString() + + ", " + ep.GetS(). + ToString() + + ", " + ep.GetT(). + ToString() + + "> • " + ep.getC(). + toString() } func (ep EqualityProblem) AxiomsToTPTPString() string { @@ -85,7 +92,10 @@ func (ep EqualityProblem) AxiomsToTPTPString() string { } func (ep EqualityProblem) ToTPTPString() string { - return ep.GetS().ToMappedString(AST.DefaultMapString, false) + " = " + ep.GetT().ToMappedString(AST.DefaultMapString, false) + return ep.GetS(). + ToMappedString(AST.DefaultMapString, false) + + " = " + ep.GetT(). + ToMappedString(AST.DefaultMapString, false) } /* Apply a substitution on an equality problem */ @@ -95,7 +105,10 @@ func (ep EqualityProblem) applySubstitution(s Unif.Substitutions) EqualityProble new_equalities := ep.GetE() if !ep.getC().isEmpty() { - Glob.PrintError("EQ-AS", fmt.Sprintf("Constraint not null in applySubstitution : %v", ep.getC().toString())) + Glob.PrintError( + "EQ-AS", + fmt.Sprintf("Constraint not null in applySubstitution : %v", ep.getC().toString()), + ) } for _, subst := range s { @@ -131,7 +144,14 @@ func makeEqualityProblemList(E Equalities, goal []eqStruct.TermPair) EqualityPro } func makeEqualityProblem(E Equalities, s AST.Term, t AST.Term, c ConstraintStruct) EqualityProblem { - return EqualityProblem{makeDataStructFromEqualities(E.copy()), makeEQMapFromEqualities(E.copy()), E.copy(), s.Copy(), t.Copy(), c.copy()} + return EqualityProblem{ + makeDataStructFromEqualities(E.copy()), + makeEQMapFromEqualities(E.copy()), + E.copy(), + s.Copy(), + t.Copy(), + c.copy(), + } } /* Take a list of equalities and build the corresponding code tree */ diff --git a/src/Mods/equality/bse/equality_problem_list.go b/src/Mods/equality/bse/equality_problem_list.go index f29243bc..12f46a29 100644 --- a/src/Mods/equality/bse/equality_problem_list.go +++ b/src/Mods/equality/bse/equality_problem_list.go @@ -115,7 +115,9 @@ func (epml EqualityProblemMultiList) ToTPTPString(isSat bool) string { problemName := os.Args[len(os.Args)-1] problemName = problemName[:len(problemName)-2] parts := strings.Split(problemName, "/") - problemName = strings.ToLower(strings.ReplaceAll(parts[len(parts)-1], "+", "plus") + "eq" + strconv.Itoa(eqCpt)) + problemName = strings.ToLower( + strings.ReplaceAll(parts[len(parts)-1], "+", "plus") + "eq" + strconv.Itoa(eqCpt), + ) if !isSat { problemName = problemName + "un" @@ -178,17 +180,29 @@ func makeEmptyEqualityProblemMultiList() EqualityProblemMultiList { /*** Functions ***/ /* Build an equalit problem multilist from a list of inequation */ -func buildEqualityProblemMultiListFromNEQ(neq Inequalities, eq Equalities) EqualityProblemMultiList { +func buildEqualityProblemMultiListFromNEQ( + neq Inequalities, + eq Equalities, +) EqualityProblemMultiList { res := makeEmptyEqualityProblemMultiList() for _, neq_pair := range neq { - x := makeEqualityProblem(eq.copy(), neq_pair.GetT1(), neq_pair.GetT2(), makeEmptyConstraintStruct()) + x := makeEqualityProblem( + eq.copy(), + neq_pair.GetT1(), + neq_pair.GetT2(), + makeEmptyConstraintStruct(), + ) res = append(res, append(makeEmptyEqualityProblemList(), x)) } return res } /* Build an equality problem list from a predicat and its negation */ -func buildEqualityProblemListFrom2Pred(p1 AST.Pred, p2 AST.Pred, eq Equalities) EqualityProblemList { +func buildEqualityProblemListFrom2Pred( + p1 AST.Pred, + p2 AST.Pred, + eq Equalities, +) EqualityProblemList { res := makeEmptyEqualityProblemList() for i := range p1.GetArgs().GetSlice() { res = append(res, makeEqualityProblem( @@ -202,7 +216,11 @@ func buildEqualityProblemListFrom2Pred(p1 AST.Pred, p2 AST.Pred, eq Equalities) } /* Build an equality problem multi list from a list of predicate. Take one predicate, search for its negation in the code tree, and if it found any, build the corresponding equality problem list */ -func buildEqualityProblemMultiListFromPredList(pred AST.Pred, tn Unif.DataStructure, equs Equalities) EqualityProblemMultiList { +func buildEqualityProblemMultiListFromPredList( + pred AST.Pred, + tn Unif.DataStructure, + equs Equalities, +) EqualityProblemMultiList { res := makeEmptyEqualityProblemMultiList() predId := pred.GetID() @@ -222,7 +240,14 @@ func buildEqualityProblemMultiListFromPredList(pred AST.Pred, tn Unif.DataStruct if found { for _, s := range complementaryPredList { - res = append(res, buildEqualityProblemListFrom2Pred(pred.Copy().(AST.Pred), s.GetForm().(AST.Pred), equs.copy())) + res = append( + res, + buildEqualityProblemListFrom2Pred( + pred.Copy().(AST.Pred), + s.GetForm().(AST.Pred), + equs.copy(), + ), + ) } } @@ -230,7 +255,11 @@ func buildEqualityProblemMultiListFromPredList(pred AST.Pred, tn Unif.DataStruct } /* Take a list of form and build an equality problem list, corresponding to thoses related to a predicate and its negation */ -func buildEqualityProblemMultiListFromFormList(fl *AST.FormList, tn Unif.DataStructure, eq Equalities) EqualityProblemMultiList { +func buildEqualityProblemMultiListFromFormList( + fl *AST.FormList, + tn Unif.DataStructure, + eq Equalities, +) EqualityProblemMultiList { res := makeEmptyEqualityProblemMultiList() for _, p := range fl.Slice() { if pt, ok := p.(AST.Pred); ok { @@ -245,17 +274,24 @@ func buildEqualityProblemMultiListFromFormList(fl *AST.FormList, tn Unif.DataStr return res } -/** +/* +* * Take a form list * Retun a lis of independent problem list (from predicate and negation) + a boolean, true if there is equality in the formula list, false otherwise -**/ -func buildEqualityProblemMultiList(fl *AST.FormList, tp, tn Unif.DataStructure) (EqualityProblemMultiList, bool) { +* + */ +func buildEqualityProblemMultiList( + fl *AST.FormList, + tp, tn Unif.DataStructure, +) (EqualityProblemMultiList, bool) { res := makeEmptyEqualityProblemMultiList() eq := retrieveEqualities(tp.Copy()) if len(eq) == 0 { return res, false } - res = append(res, buildEqualityProblemMultiListFromNEQ(retrieveInequalities(tn.Copy()), eq.copy())...) + res = append( + res, + buildEqualityProblemMultiListFromNEQ(retrieveInequalities(tn.Copy()), eq.copy())...) debug( Lib.MkLazy(func() string { return fmt.Sprintf("Res after FromNEQ : %v", res.ToString()) }), ) diff --git a/src/Mods/equality/bse/equality_rules_apply.go b/src/Mods/equality/bse/equality_rules_apply.go index 40d6e8ae..2af389c1 100644 --- a/src/Mods/equality/bse/equality_rules_apply.go +++ b/src/Mods/equality/bse/equality_rules_apply.go @@ -48,7 +48,9 @@ import ( func applyRule(rs ruleStruct, ep EqualityProblem, parent chan answerEP, father_id uint64) { debug(Lib.MkLazy(func() string { return fmt.Sprintf("Child of %v", father_id) })) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("EQ before applying rule %v", ep.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("EQ before applying rule %v", ep.ToString()) }, + ), ) debug( Lib.MkLazy(func() string { return fmt.Sprintf("Apply rule %v", rs.toString()) }), @@ -70,7 +72,14 @@ func applyLeftRule(rs ruleStruct, ep EqualityProblem, father_chan chan answerEP, debug( Lib.MkLazy(func() string { return "Apply left rule" }), ) - is_consistant_with_lpo, new_term, new_cl := applyEQRule(rs.getL(), rs.getR(), rs.getLPrime(), rs.getS(), rs.getT(), ep.getC()) + is_consistant_with_lpo, new_term, new_cl := applyEQRule( + rs.getL(), + rs.getR(), + rs.getLPrime(), + rs.getS(), + rs.getT(), + ep.getC(), + ) if is_consistant_with_lpo { debug( @@ -83,9 +92,17 @@ func applyLeftRule(rs ruleStruct, ep EqualityProblem, father_chan chan answerEP, new_eq_list[rs.getIndexEQList()] = eqStruct.MakeTermPair(rs.getS(), new_term.Copy()) } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("New EQ list : %v", new_eq_list.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("New EQ list : %v", new_eq_list.ToString()) }, + ), + ) + tryEqualityReasoningProblem( + makeEqualityProblem(new_eq_list, ep.GetS(), ep.GetT(), new_cl), + father_chan, + rs.getIndexEQList(), + LEFT, + father_id, ) - tryEqualityReasoningProblem(makeEqualityProblem(new_eq_list, ep.GetS(), ep.GetT(), new_cl), father_chan, rs.getIndexEQList(), LEFT, father_id) } else { debug( Lib.MkLazy(func() string { return "Not consistant with LPO, send nil" }), @@ -96,19 +113,37 @@ func applyLeftRule(rs ruleStruct, ep EqualityProblem, father_chan chan answerEP, } /* Apply right rigid basic superposition rule */ -func applyRightRule(rs ruleStruct, ep EqualityProblem, father_chan chan answerEP, father_id uint64) { +func applyRightRule( + rs ruleStruct, + ep EqualityProblem, + father_chan chan answerEP, + father_id uint64, +) { debug( Lib.MkLazy(func() string { return "Apply right rule" }), ) - is_consistant_with_lpo, new_term, new_cl := applyEQRule(rs.getL(), rs.getR(), rs.getLPrime(), rs.getS(), rs.getT(), ep.getC()) + is_consistant_with_lpo, new_term, new_cl := applyEQRule( + rs.getL(), + rs.getR(), + rs.getLPrime(), + rs.getS(), + rs.getT(), + ep.getC(), + ) if is_consistant_with_lpo { debug( Lib.MkLazy(func() string { return fmt.Sprintf("New term : %v", new_term.ToString()) }), ) if rs.getIsSModified() { - tryEqualityReasoningProblem(makeEqualityProblem(ep.copy().GetE(), new_term.Copy(), rs.getT(), new_cl), father_chan, rs.getIndexEQList(), RIGHT, father_id) + tryEqualityReasoningProblem( + makeEqualityProblem(ep.copy().GetE(), new_term.Copy(), rs.getT(), new_cl), + father_chan, + rs.getIndexEQList(), + RIGHT, + father_id, + ) } else { tryEqualityReasoningProblem(makeEqualityProblem(ep.copy().GetE(), rs.getS(), new_term.Copy(), new_cl), father_chan, rs.getIndexEQList(), RIGHT, father_id) } @@ -128,7 +163,10 @@ func applyRightRule(rs ruleStruct, ep EqualityProblem, father_chan chan answerEP * s and t * sub_term_of s is a subterm of s unifible with l **/ -func applyEQRule(l, r, sub_term_of_s, s, t AST.Term, cs ConstraintStruct) (bool, AST.Term, ConstraintStruct) { +func applyEQRule( + l, r, sub_term_of_s, s, t AST.Term, + cs ConstraintStruct, +) (bool, AST.Term, ConstraintStruct) { debug( Lib.MkLazy(func() string { return "Apply eq rule" }), ) @@ -140,7 +178,9 @@ func applyEQRule(l, r, sub_term_of_s, s, t AST.Term, cs ConstraintStruct) (bool, ) new_s := s.Copy().ReplaceSubTermBy(sub_term_of_s, r) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("s = %v, new_s = %v", s.ToString(), new_s.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("s = %v, new_s = %v", s.ToString(), new_s.ToString()) }, + ), ) constraints_list := cs.copy() @@ -150,7 +190,9 @@ func applyEQRule(l, r, sub_term_of_s, s, t AST.Term, cs ConstraintStruct) (bool, if !constraints_list.appendIfConsistant(MakeConstraint(PREC, eqStruct.MakeTermPair(t, s))) { return false, nil, makeEmptyConstraintStruct() } - if !constraints_list.appendIfConsistant(MakeConstraint(EQ, eqStruct.MakeTermPair(l, sub_term_of_s))) { + if !constraints_list.appendIfConsistant( + MakeConstraint(EQ, eqStruct.MakeTermPair(l, sub_term_of_s)), + ) { return false, nil, makeEmptyConstraintStruct() } return true, new_s, constraints_list diff --git a/src/Mods/equality/bse/equality_rules_reasoning.go b/src/Mods/equality/bse/equality_rules_reasoning.go index 1346031d..3c7816e7 100644 --- a/src/Mods/equality/bse/equality_rules_reasoning.go +++ b/src/Mods/equality/bse/equality_rules_reasoning.go @@ -51,7 +51,10 @@ type BasicEqualityStruct struct { } func NewBasicEqualityStruct() eqStruct.EqualityStruct { - return &BasicEqualityStruct{Glob.NewList[eqStruct.TermPair](), Glob.NewList[*Glob.List[eqStruct.TermPair]]()} + return &BasicEqualityStruct{ + Glob.NewList[eqStruct.TermPair](), + Glob.NewList[*Glob.List[eqStruct.TermPair]](), + } } func (bes *BasicEqualityStruct) AddAssumption(assumption eqStruct.TermPair) { @@ -80,7 +83,9 @@ func (bes *BasicEqualityStruct) Solve() (subs []Unif.Substitutions, success bool epl := makeEqualityProblemList(bes.assumptions.Slice(), goal.Slice()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("iteration on EPL : %v", epl.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("iteration on EPL : %v", epl.ToString()) }, + ), ) if has_solution, subst_res_tmp := equalityReasoningList(epl); has_solution { debug( @@ -92,7 +97,10 @@ func (bes *BasicEqualityStruct) Solve() (subs []Unif.Substitutions, success bool ) found = true for subst_res_tmp_element := range subst_res_tmp { - substs_res = Unif.AppendIfNotContainsSubst(substs_res, subst_res_tmp[subst_res_tmp_element]) + substs_res = Unif.AppendIfNotContainsSubst( + substs_res, + subst_res_tmp[subst_res_tmp_element], + ) } } } @@ -122,7 +130,10 @@ func (bes *BasicEqualityStruct) Copy() eqStruct.EqualityStruct { } // Add the new equality problems to the EqualityStruct and run the equality reasoning. -func RunEqualityReasoning(es eqStruct.EqualityStruct, epml EqualityProblemMultiList) (bool, []Unif.Substitutions) { +func RunEqualityReasoning( + es eqStruct.EqualityStruct, + epml EqualityProblemMultiList, +) (bool, []Unif.Substitutions) { for _, eq := range epml[0][0].GetE() { es.AddAssumption(eq) } @@ -141,14 +152,18 @@ func RunEqualityReasoning(es eqStruct.EqualityStruct, epml EqualityProblemMultiL return found, subs } -/** +/* +* * EqualityReasoningList * Data : an equality problem list (EqualityProblemList), corresponding to an inequality or two complementary predicates * Result : true if all of the problem in the list agrees on at least one substitution, and the corresponding substitutions -**/ +* + */ func equalityReasoningList(epl EqualityProblemList) (bool, []Unif.Substitutions) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Start of Equality reasoning list : %v", epl.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Start of Equality reasoning list : %v", epl.ToString()) }, + ), ) substs_res := []Unif.Substitutions{} @@ -175,9 +190,14 @@ func equalityReasoningList(epl EqualityProblemList) (bool, []Unif.Substitutions) } /* return true if at least on subst on the subst list returns result, and the corresponding substitution list */ -func manageEqualityReasoningProblem(ep EqualityProblem, sl []Unif.Substitutions) (bool, []Unif.Substitutions) { +func manageEqualityReasoningProblem( + ep EqualityProblem, + sl []Unif.Substitutions, +) (bool, []Unif.Substitutions) { debug( - Lib.MkLazy(func() string { return "Start on equality reasoning problem with apply subst" }), + Lib.MkLazy( + func() string { return "Start on equality reasoning problem with apply subst" }, + ), ) if len(sl) == 0 { subst := launchEqualityReasoningProblem(ep) diff --git a/src/Mods/equality/bse/equality_rules_try_apply.go b/src/Mods/equality/bse/equality_rules_try_apply.go index 13f493fa..575b74b4 100644 --- a/src/Mods/equality/bse/equality_rules_try_apply.go +++ b/src/Mods/equality/bse/equality_rules_try_apply.go @@ -54,8 +54,12 @@ func tryApplyLeftRules(ep EqualityProblem, index_begin int) ruleStructList { i := index_begin for i < len(ep.GetE()) { eq_pair := ep.GetE()[i] - res = append(res, tryApplyRuleAux(eq_pair.GetT1(), eq_pair.GetT2(), ep.copy(), LEFT, true, i)...) - res = append(res, tryApplyRuleAux(eq_pair.GetT2(), eq_pair.GetT1(), ep.copy(), LEFT, false, i)...) + res = append( + res, + tryApplyRuleAux(eq_pair.GetT1(), eq_pair.GetT2(), ep.copy(), LEFT, true, i)...) + res = append( + res, + tryApplyRuleAux(eq_pair.GetT2(), eq_pair.GetT1(), ep.copy(), LEFT, false, i)...) i++ } debug( @@ -79,7 +83,13 @@ func tryApplyRightRules(ep EqualityProblem) ruleStructList { } /* Set rule's parameter */ -func tryApplyRuleAux(t1, t2 AST.Term, ep EqualityProblem, ruleType int, is_s_modified bool, index int) ruleStructList { +func tryApplyRuleAux( + t1, t2 AST.Term, + ep EqualityProblem, + ruleType int, + is_s_modified bool, + index int, +) ruleStructList { res := tryApplyRuleCompute(t1.Copy(), t2.Copy(), ep.copy(), ruleType) new_res := ruleStructList{} for _, r := range res { @@ -121,7 +131,9 @@ func tryApplyRuleCompute(s, t AST.Term, ep EqualityProblem, type_rule int) ruleS // for each l' substerm of s, return a list (l', l) unifiable list_l_prime_l := searchUnifBewteenListAndEq(subterms_of_s, ep.getETree()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("len unifiable subterms found : %v", len(list_l_prime_l)) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("len unifiable subterms found : %v", len(list_l_prime_l)) }, + ), ) // Now, for each (l', l), retrieve the r corresponding to the l @@ -129,7 +141,13 @@ func tryApplyRuleCompute(s, t AST.Term, ep EqualityProblem, type_rule int) ruleS } /* Retrieve the last membre of rule struct and return the list */ -func connectLAndR(list_l_prime_l []eqStruct.TermPair, ep EqualityProblem, s AST.Term, t AST.Term, type_rule int) ruleStructList { +func connectLAndR( + list_l_prime_l []eqStruct.TermPair, + ep EqualityProblem, + s AST.Term, + t AST.Term, + type_rule int, +) ruleStructList { res := ruleStructList{} for _, l_prime_l_pair := range list_l_prime_l { @@ -163,7 +181,17 @@ func connectLAndR(list_l_prime_l []eqStruct.TermPair, ep EqualityProblem, s AST. debug( Lib.MkLazy(func() string { return "Try apply rule ok !" }), ) - res = append(res, makeRuleStruct(type_rule, l_prime_l_pair.GetT2(), r.Copy(), l_prime_l_pair.GetT1(), s.Copy(), t.Copy())) + res = append( + res, + makeRuleStruct( + type_rule, + l_prime_l_pair.GetT2(), + r.Copy(), + l_prime_l_pair.GetT1(), + s.Copy(), + t.Copy(), + ), + ) } else { debug( Lib.MkLazy(func() string { return "Don't apply an equality on itself" }), @@ -175,7 +203,10 @@ func connectLAndR(list_l_prime_l []eqStruct.TermPair, ep EqualityProblem, s AST. } /* return all the pair (l, l') unifiable */ -func searchUnifBewteenListAndEq(tl Lib.List[AST.Term], tree Unif.DataStructure) []eqStruct.TermPair { +func searchUnifBewteenListAndEq( + tl Lib.List[AST.Term], + tree Unif.DataStructure, +) []eqStruct.TermPair { debug(Lib.MkLazy(func() string { return fmt.Sprintf( "Searching unfication between %v and the eq tree", @@ -189,7 +220,9 @@ func searchUnifBewteenListAndEq(tl Lib.List[AST.Term], tree Unif.DataStructure) Lib.MkLazy(func() string { return "------------------------------------------" }), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Current subterm : %v", t_prime.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Current subterm : %v", t_prime.ToString()) }, + ), ) if !t_prime.IsMeta() { res, tl := checkUnifInTree(t_prime, tree) @@ -199,7 +232,9 @@ func searchUnifBewteenListAndEq(tl Lib.List[AST.Term], tree Unif.DataStructure) ) for _, t := range tl.GetSlice() { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Unif found with : %v", t.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Unif found with : %v", t.ToString()) }, + ), ) term_pair_list = append(term_pair_list, eqStruct.MakeTermPair(t_prime, t)) } diff --git a/src/Mods/equality/bse/equality_solve_reasoning_problem.go b/src/Mods/equality/bse/equality_solve_reasoning_problem.go index dd50c1f1..679ae523 100644 --- a/src/Mods/equality/bse/equality_solve_reasoning_problem.go +++ b/src/Mods/equality/bse/equality_solve_reasoning_problem.go @@ -55,7 +55,12 @@ func launchEqualityReasoningProblem(ep EqualityProblem) []Unif.Substitutions { } /* try equalityReasoningProblem */ -func tryEqualityReasoningProblem(ep EqualityProblem, father_chan chan answerEP, last_applied_rule_index, last_applied_rule_type int, father_id uint64) { +func tryEqualityReasoningProblem( + ep EqualityProblem, + father_chan chan answerEP, + last_applied_rule_index, last_applied_rule_type int, + father_id uint64, +) { debug( Lib.MkLazy(func() string { return fmt.Sprintf("Child of %v", father_id) }), ) @@ -63,7 +68,12 @@ func tryEqualityReasoningProblem(ep EqualityProblem, father_chan chan answerEP, case <-father_chan: // kil order default: // No kill order, let's apply the next rules. - found, substs := equalityReasoningProblem(ep, father_chan, last_applied_rule_index, last_applied_rule_type) + found, substs := equalityReasoningProblem( + ep, + father_chan, + last_applied_rule_index, + last_applied_rule_type, + ) debug( Lib.MkLazy(func() string { return "Send solution to father_chan" }), ) @@ -79,7 +89,11 @@ func tryEqualityReasoningProblem(ep EqualityProblem, father_chan chan answerEP, } /* launch an equality reasoning problem resolution. Stop when the first solution is found */ -func equalityReasoningProblem(ep EqualityProblem, father_chan chan answerEP, last_applied_rule_index, last_applied_rule_type int) (bool, []Unif.Substitutions) { +func equalityReasoningProblem( + ep EqualityProblem, + father_chan chan answerEP, + last_applied_rule_index, last_applied_rule_type int, +) (bool, []Unif.Substitutions) { debug(Lib.MkLazy(func() string { return fmt.Sprintf("EP : %v", ep.ToString()) })) substs_res := []Unif.Substitutions{} unif_found := false @@ -108,14 +122,21 @@ func equalityReasoningProblem(ep EqualityProblem, father_chan chan answerEP, las } // Apply available rule - solution_found, solution_subst := manageRLRules(ep, father_chan, last_applied_rule_index, last_applied_rule_type) + solution_found, solution_subst := manageRLRules( + ep, + father_chan, + last_applied_rule_index, + last_applied_rule_type, + ) if solution_found { unif_found = true substs_res = append(substs_res, solution_subst...) } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Send : %v !", Unif.SubstListToString(substs_res)) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Send : %v !", Unif.SubstListToString(substs_res)) }, + ), ) return unif_found, substs_res } @@ -123,11 +144,17 @@ func equalityReasoningProblem(ep EqualityProblem, father_chan chan answerEP, las /*** Launch rules ***/ /* Manage application of right and left rules - // bewteen same type, sequential bewteen diffrent types */ -func manageRLRules(ep EqualityProblem, father chan answerEP, last_applied_rule_index, last_applied_rule_type int) (bool, []Unif.Substitutions) { +func manageRLRules( + ep EqualityProblem, + father chan answerEP, + last_applied_rule_index, last_applied_rule_type int, +) (bool, []Unif.Substitutions) { // Compute right rule debug(Lib.MkLazy(func() string { return "Try apply right rules !" })) - rules_to_apply := tryApplyRightRules(ep) // TODO : ne chercher la contradiction seulement avec l'index donné + rules_to_apply := tryApplyRightRules( + ep, + ) // TODO : ne chercher la contradiction seulement avec l'index donné debug( Lib.MkLazy(func() string { return fmt.Sprintf( @@ -163,7 +190,11 @@ func manageRLRules(ep EqualityProblem, father chan answerEP, last_applied_rule_i } } -func manageRule(ep EqualityProblem, rsl ruleStructList, father chan answerEP) (bool, []Unif.Substitutions) { +func manageRule( + ep EqualityProblem, + rsl ruleStructList, + father chan answerEP, +) (bool, []Unif.Substitutions) { chan_tab := tryLaunchRule(ep, rsl) return selectAnswerEP(chan_tab, father) } @@ -186,7 +217,10 @@ func launchApplyRules(rs ruleStruct, ep EqualityProblem) chan answerEP { /*** Retrieve result ***/ /* Wait for children to close. Return chen the fisrt child with a substitution answer */ -func selectAnswerEP(chan_tab [](chan answerEP), chan_parent chan answerEP) (bool, []Unif.Substitutions) { +func selectAnswerEP( + chan_tab [](chan answerEP), + chan_parent chan answerEP, +) (bool, []Unif.Substitutions) { // Instantiation cases := makeCases(chan_tab, chan_parent) hasAnswered := make([]bool, len(chan_tab)) // Everything to false @@ -250,7 +284,10 @@ func makeCases(chan_tab [](chan answerEP), chan_parent chan answerEP) []reflect. cases[i] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(chan_)} } // Parent - cases[len(chan_tab)] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(chan_parent)} + cases[len(chan_tab)] = reflect.SelectCase{ + Dir: reflect.SelectRecv, + Chan: reflect.ValueOf(chan_parent), + } return cases } diff --git a/src/Mods/equality/bse/equality_test.go b/src/Mods/equality/bse/equality_test.go index 4dcc83dc..95555f29 100644 --- a/src/Mods/equality/bse/equality_test.go +++ b/src/Mods/equality/bse/equality_test.go @@ -227,11 +227,17 @@ func initTestVariable() { neq_x_a = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(x, a), []Typing.TypeApp{})) neq_a_b = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(a, b), []Typing.TypeApp{})) neq_a_d = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(a, d), []Typing.TypeApp{})) - neq_gggx_x = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(gggx, x), []Typing.TypeApp{})) + neq_gggx_x = Core.MakerNot( + Core.MakerPred(AST.Id_eq, Core.NewTermList(gggx, x), []Typing.TypeApp{}), + ) neq_fx_a = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(fx, a), []Typing.TypeApp{})) neq_fx_x = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(fx, x), []Typing.TypeApp{})) - neq_fab_fcd = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(fab, fcd), []Typing.TypeApp{})) - neq_fb_fc = Core.MakerNot(Core.MakerPred(AST.Id_eq, Core.NewTermList(fb, fc), []Typing.TypeApp{})) + neq_fab_fcd = Core.MakerNot( + Core.MakerPred(AST.Id_eq, Core.NewTermList(fab, fcd), []Typing.TypeApp{}), + ) + neq_fb_fc = Core.MakerNot( + Core.MakerPred(AST.Id_eq, Core.NewTermList(fb, fc), []Typing.TypeApp{}), + ) // Predicates pggab = Core.MakerPred(p_id, Core.NewTermList(gga, b), []Typing.TypeApp{}) @@ -305,7 +311,11 @@ func TestConstraints1(t *testing.T) { append := cs.appendIfConsistant(constraint_ffx_x) if append || len(cs.getPrec()) > 0 { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected not consistant and empty PREC list", append, cs.getPrec().toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected not consistant and empty PREC list", + append, + cs.getPrec().toString(), + ) } } @@ -317,7 +327,11 @@ func TestConstraints2(t *testing.T) { append := cs.appendIfConsistant(constraint_x_ffx) if !append || len(cs.getPrec()) > 0 { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected consistant and empty PREC list", append, cs.getPrec().toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected consistant and empty PREC list", + append, + cs.getPrec().toString(), + ) } } @@ -330,7 +344,12 @@ func TestConstraints3(t *testing.T) { append := cs.appendIfConsistant(constraint_fx_a) if !append || len(cs.getPrec()) != 1 || !cs.getPrec()[0].equals(constraint_fx_a) { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected consistant and %v", append, cs.getPrec().toString(), constraint_fx_a.toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected consistant and %v", + append, + cs.getPrec().toString(), + constraint_fx_a.toString(), + ) } } @@ -346,14 +365,24 @@ func TestConstaints4(t *testing.T) { res_constraint_1 := cs.appendIfConsistant(constraint_fx_a) if !res_constraint_1 || len(cs.getPrec()) != 1 || !cs.getPrec()[0].equals(constraint_fx_a) { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected consistant and %v", res_constraint_1, cs.getPrec().toString(), constraint_fx_a.toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected consistant and %v", + res_constraint_1, + cs.getPrec().toString(), + constraint_fx_a.toString(), + ) } tp_a_fx := eqStruct.MakeTermPair(a, fx) constraint_a_fx := MakeConstraint(PREC, tp_a_fx) res_constraint_2 := cs.appendIfConsistant(constraint_a_fx) if res_constraint_2 || len(cs.getPrec()) != 1 || !cs.getPrec()[0].equals(constraint_fx_a) { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected not consistant and %v", res_constraint_2, cs.getPrec().toString(), constraint_fx_a.toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected not consistant and %v", + res_constraint_2, + cs.getPrec().toString(), + constraint_fx_a.toString(), + ) } } @@ -366,7 +395,11 @@ func TestConstraints5(t *testing.T) { constraint_ffabc_fafbc := MakeConstraint(PREC, tp_ffabc_fafbc) res_constraint_1 := cs.appendIfConsistant(constraint_ffabc_fafbc) if res_constraint_1 || len(cs.getPrec()) > 0 { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected not consistant and empty PREC list", res_constraint_1, cs.getPrec().toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected not consistant and empty PREC list", + res_constraint_1, + cs.getPrec().toString(), + ) } /* Consistant but not relevant */ @@ -374,7 +407,11 @@ func TestConstraints5(t *testing.T) { constraint_fafbc_ffabc := MakeConstraint(PREC, tp_fafbc_ffabc) res_constraint_2 := cs.appendIfConsistant(constraint_fafbc_ffabc) if !res_constraint_2 || len(cs.getPrec()) > 0 { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected consistant and empty PREC list", res_constraint_1, cs.getPrec().toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected consistant and empty PREC list", + res_constraint_1, + cs.getPrec().toString(), + ) } } @@ -386,7 +423,11 @@ func TestConstaintes6(t *testing.T) { constraint_fafbc_ffabc := MakeConstraint(PREC, tp_fxfyz_ffxyz) append := cs.appendIfConsistant(constraint_fafbc_ffabc) if !append || len(cs.getPrec()) > 0 { - t.Fatalf("Error: %v and %v is not the expected PREC list. Expected consistant and empty PREC list", append, cs.getPrec().toString()) + t.Fatalf( + "Error: %v and %v is not the expected PREC list. Expected consistant and empty PREC list", + append, + cs.getPrec().toString(), + ) } } diff --git a/src/Mods/equality/bse/lpo.go b/src/Mods/equality/bse/lpo.go index 314c5916..1b87498c 100644 --- a/src/Mods/equality/bse/lpo.go +++ b/src/Mods/equality/bse/lpo.go @@ -67,7 +67,9 @@ func makeEmptyCompareStruct() compareStruct { **/ func compareLPO(s, t AST.Term) compareStruct { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Compare %v and %v", s.ToString(), t.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Compare %v and %v", s.ToString(), t.ToString()) }, + ), ) switch s_type := s.(type) { case AST.Fun: @@ -116,12 +118,14 @@ func compareLPO(s, t AST.Term) compareStruct { return makeCompareStruct(0, false, s, t) } -/** +/* +* * Compare a metavariable and a function. * Return code comes for the compare function and code must be 1 or -1. It correspond to the code to return of the CompreMetaFun fits the LPO. * It's needed to keep the order. * For example, x < f(x) is ok but f(x) < x isn't -**/ +* + */ func compareMetaFun(m AST.Meta, f AST.Fun, return_code int) compareStruct { debug( Lib.MkLazy(func() string { return "Compare Meta Fun" }), @@ -129,13 +133,17 @@ func compareMetaFun(m AST.Meta, f AST.Fun, return_code int) compareStruct { // Check argument inside f if found, res := compareMetaFunInside(m, f, return_code); found { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Found after compare inside : %v", res) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Found after compare inside : %v", res) }, + ), ) return res } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Not found and return_code is %v", return_code) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Not found and return_code is %v", return_code) }, + ), ) // f has no args or all respect LPO if return_code == 1 { @@ -240,7 +248,14 @@ func caseFEqualsG(s, t AST.Fun) (bool, compareStruct) { Lib.MkLazy(func() string { return "Case F = G" }), ) if s.GetArgs().Len() != t.GetArgs().Len() { - Glob.PrintError("F=G", fmt.Sprintf("Error : %v and %v don't have the same number of arguments", s.GetID().ToString(), t.GetID().ToString())) + Glob.PrintError( + "F=G", + fmt.Sprintf( + "Error : %v and %v don't have the same number of arguments", + s.GetID().ToString(), + t.GetID().ToString(), + ), + ) return true, makeCompareStruct(0, false, nil, nil) } diff --git a/src/Mods/equality/bse/rule_struct.go b/src/Mods/equality/bse/rule_struct.go index 1725b59b..67ef9123 100644 --- a/src/Mods/equality/bse/rule_struct.go +++ b/src/Mods/equality/bse/rule_struct.go @@ -101,7 +101,23 @@ func (r ruleStruct) toString() string { if r.getRule() == RIGHT { type_rule = "RIGHT" } - return "[ type = " + type_rule + ", s = " + r.getS().ToString() + ", t = " + r.getT().ToString() + ", l' = " + r.getLPrime().ToString() + ", l = " + r.getL().ToString() + ", r = " + r.getR().ToString() + ", is s modified = " + fmt.Sprintf("%v", r.getIsSModified()) + ", index = " + fmt.Sprintf("%v", r.getIndexEQList()) + " ]" + return "[ type = " + type_rule + ", s = " + r.getS(). + ToString() + + ", t = " + r.getT(). + ToString() + + ", l' = " + r.getLPrime(). + ToString() + + ", l = " + r.getL(). + ToString() + + ", r = " + r.getR(). + ToString() + + ", is s modified = " + fmt.Sprintf( + "%v", + r.getIsSModified(), + ) + ", index = " + fmt.Sprintf( + "%v", + r.getIndexEQList(), + ) + " ]" } func makeRuleStruct(rule int, l, r, l_prime, s, t AST.Term) ruleStruct { return ruleStruct{rule, l, r, l_prime, s, t, true, -1} diff --git a/src/Mods/equality/eqStruct/term_pair.go b/src/Mods/equality/eqStruct/term_pair.go index 8009e621..830be98f 100644 --- a/src/Mods/equality/eqStruct/term_pair.go +++ b/src/Mods/equality/eqStruct/term_pair.go @@ -94,7 +94,10 @@ func (tp TermPair) ToString() string { return tp.GetT1().ToString() + " ≈ " + tp.GetT2().ToString() } func (tp TermPair) ToTPTPString() string { - return tp.GetT1().ToMappedString(AST.DefaultMapString, false) + " = " + tp.GetT2().ToMappedString(AST.DefaultMapString, false) + return tp.GetT1(). + ToMappedString(AST.DefaultMapString, false) + + " = " + tp.GetT2(). + ToMappedString(AST.DefaultMapString, false) } func MakeTermPair(t1, t2 AST.Term) TermPair { return TermPair{t1.Copy(), t2.Copy()} diff --git a/src/Mods/equality/sateq/problem.go b/src/Mods/equality/sateq/problem.go index 7c409c6b..4064f83a 100644 --- a/src/Mods/equality/sateq/problem.go +++ b/src/Mods/equality/sateq/problem.go @@ -167,8 +167,10 @@ func (problem *Problem) mergeEquivalenceClasses(ec1, ec2 *eqClass) { } // update indexes (see invariant above) - problem.partitionIndex[ecMerged].Append(problem.partitionIndex[ecDeleted].Slice()...) // the entries of partitionIndex are disjoint - problem.supertermIndex[ecMerged].AppendIfNotContains(problem.supertermIndex[ecDeleted].Slice()...) + problem.partitionIndex[ecMerged].Append( + problem.partitionIndex[ecDeleted].Slice()...) // the entries of partitionIndex are disjoint + problem.supertermIndex[ecMerged].AppendIfNotContains( + problem.supertermIndex[ecDeleted].Slice()...) delete(problem.partitionIndex, ecDeleted) delete(problem.supertermIndex, ecDeleted) @@ -186,14 +188,22 @@ func (problem *Problem) mergeEquivalenceClasses(ec1, ec2 *eqClass) { } func (problem *Problem) AddAssumption(eq eqStruct.TermPair) { - problem.mergeEquivalenceClasses(problem.getEquivalenceClass(eq.GetT1()), problem.getEquivalenceClass(eq.GetT2())) + problem.mergeEquivalenceClasses( + problem.getEquivalenceClass(eq.GetT1()), + problem.getEquivalenceClass(eq.GetT2()), + ) } func (problem *Problem) AddGoal(goal []eqStruct.TermPair) { g := Glob.NewList[*Glob.BasicPair[*eqClass, *eqClass]]() for _, eq := range goal { - g.AppendIfNotContains(Glob.NewBasicPair(problem.getEquivalenceClass(eq.GetT1()), problem.getEquivalenceClass(eq.GetT2()))) + g.AppendIfNotContains( + Glob.NewBasicPair( + problem.getEquivalenceClass(eq.GetT1()), + problem.getEquivalenceClass(eq.GetT2()), + ), + ) } problem.goals.AppendIfNotContains(g) diff --git a/src/Mods/equality/sateq/satbuilder.go b/src/Mods/equality/sateq/satbuilder.go index 2a12c85b..13d4c744 100644 --- a/src/Mods/equality/sateq/satbuilder.go +++ b/src/Mods/equality/sateq/satbuilder.go @@ -116,7 +116,10 @@ func (sb *SatBuilder) buildMappingConstraints() { eci := sb.eqClasses.Get(i) for j := i + 1; j < sb.eqClasses.Len(); j++ { ecj := sb.eqClasses.Get(j) - sb.addClause(sb.getVarFromSMapping(meta, eci).Not(), sb.getVarFromSMapping(meta, ecj).Not()) + sb.addClause( + sb.getVarFromSMapping(meta, eci).Not(), + sb.getVarFromSMapping(meta, ecj).Not(), + ) } } } @@ -227,7 +230,10 @@ func (sb *SatBuilder) buildGoalConstraints() { conjunction = append(conjunction, cVar) for _, eq := range goal.Slice() { - sb.addClause(cVar.Not(), sb.getVarFromEMapping(sb.numberOfPairs, eq.GetFst(), eq.GetSnd())) + sb.addClause( + cVar.Not(), + sb.getVarFromEMapping(sb.numberOfPairs, eq.GetFst(), eq.GetSnd()), + ) } } @@ -268,7 +274,16 @@ func (sb *SatBuilder) buildTransitivityConstraints() { if !iConst.congruent(jConst) { for _, kConst := range sb.eqClasses.Slice() { if !jConst.congruent(kConst) { - oVarji, oVarkj, oVarki := sb.getVarFromOMapping(jConst, iConst), sb.getVarFromOMapping(kConst, jConst), sb.getVarFromOMapping(kConst, iConst) + oVarji, oVarkj, oVarki := sb.getVarFromOMapping( + jConst, + iConst, + ), sb.getVarFromOMapping( + kConst, + jConst, + ), sb.getVarFromOMapping( + kConst, + iConst, + ) sb.addClause(oVarji.Not(), oVarkj.Not(), oVarki) } } @@ -284,8 +299,20 @@ func (sb *SatBuilder) buildSubstitutionConstraints() { for _, eck := range sb.eqClasses.Slice() { ecj := meta.eqClass sVar, rVar := sb.getVarFromSMapping(meta, eci), sb.getVarFromRMapping(ecj, meta) - oVarjk, oVarik := sb.getVarFromOMapping(ecj, eck), sb.getVarFromOMapping(eci, eck) - oVarki, oVarkj := sb.getVarFromOMapping(eck, eci), sb.getVarFromOMapping(eck, ecj) + oVarjk, oVarik := sb.getVarFromOMapping( + ecj, + eck, + ), sb.getVarFromOMapping( + eci, + eck, + ) + oVarki, oVarkj := sb.getVarFromOMapping( + eck, + eci, + ), sb.getVarFromOMapping( + eck, + ecj, + ) sb.addClause(sVar.Not(), rVar.Not(), oVarki.Not(), oVarkj) sb.addClause(sVar.Not(), rVar.Not(), oVarjk.Not(), oVarik) diff --git a/src/Mods/equality/sateq/satbuilder_mappings.go b/src/Mods/equality/sateq/satbuilder_mappings.go index 92a7a7fd..4e8833a2 100644 --- a/src/Mods/equality/sateq/satbuilder_mappings.go +++ b/src/Mods/equality/sateq/satbuilder_mappings.go @@ -36,6 +36,7 @@ import ( ) type SMapping map[Glob.Pair[*termRecord, *eqClass]]Lit + type EMapping map[int]map[unorderedPair[*eqClass]]Lit // we make unorderedPairs of *eqClass, which is correct only as long as we don't mutate (merge) them type RMapping map[Glob.Pair[*eqClass, *termRecord]]Lit type OMapping map[Glob.Pair[*eqClass, *eqClass]]Lit @@ -120,7 +121,14 @@ func (sb *SatBuilder) getVarFromTMapping(index int, r1, r2, r3 *eqClass) Lit { if !found { sb.tMapping[index] = make(map[Glob.Pair[unorderedPair[*eqClass], *eqClass]]Lit) } - triplet := Glob.MakePair[unorderedPair[*eqClass], *eqClass](makeUnorderedPair[*eqClass](r1.representative(), r2.representative()), r3.representative()) - lit, _ := getIdAndRegister[Glob.Pair[unorderedPair[*eqClass], *eqClass]](sb, triplet, sb.tMapping[index]) + triplet := Glob.MakePair[unorderedPair[*eqClass], *eqClass]( + makeUnorderedPair[*eqClass](r1.representative(), r2.representative()), + r3.representative(), + ) + lit, _ := getIdAndRegister[Glob.Pair[unorderedPair[*eqClass], *eqClass]]( + sb, + triplet, + sb.tMapping[index], + ) return lit } diff --git a/src/Mods/equality/sateq/subsgatherer.go b/src/Mods/equality/sateq/subsgatherer.go index 3fd60f13..b170fdaf 100644 --- a/src/Mods/equality/sateq/subsgatherer.go +++ b/src/Mods/equality/sateq/subsgatherer.go @@ -38,14 +38,21 @@ import ( "github.com/GoelandProver/Goeland/Unif" ) -func gatherSubs(truthValues map[Lit]bool, sMapping map[Glob.Pair[*termRecord, *eqClass]]Lit, rMapping map[Glob.Pair[*eqClass, *termRecord]]Lit) (subs []Unif.Substitutions, success bool) { +func gatherSubs( + truthValues map[Lit]bool, + sMapping map[Glob.Pair[*termRecord, *eqClass]]Lit, + rMapping map[Glob.Pair[*eqClass, *termRecord]]Lit, +) (subs []Unif.Substitutions, success bool) { sub := getSubstitution(truthValues, sMapping) correspondence := getTranslation(truthValues, rMapping) return translateSub(sub, correspondence), true } -func getSubstitution(truthValue map[Lit]bool, sMapping map[Glob.Pair[*termRecord, *eqClass]]Lit) map[*termRecord]*eqClass { +func getSubstitution( + truthValue map[Lit]bool, + sMapping map[Glob.Pair[*termRecord, *eqClass]]Lit, +) map[*termRecord]*eqClass { subsMap := make(map[*termRecord]*eqClass) for pair, lit := range sMapping { @@ -57,7 +64,10 @@ func getSubstitution(truthValue map[Lit]bool, sMapping map[Glob.Pair[*termRecord return subsMap } -func getTranslation(truthValue map[Lit]bool, rMapping map[Glob.Pair[*eqClass, *termRecord]]Lit) map[*eqClass]*termRecord { +func getTranslation( + truthValue map[Lit]bool, + rMapping map[Glob.Pair[*eqClass, *termRecord]]Lit, +) map[*eqClass]*termRecord { transMap := make(map[*eqClass]*termRecord) for firstLit, assignedTrue := range truthValue { @@ -87,7 +97,10 @@ func translate(toTranslate *eqClass, correspondence map[*eqClass]*termRecord) AS } } -func translateSub(sub map[*termRecord]*eqClass, correspondence map[*eqClass]*termRecord) []Unif.Substitutions { +func translateSub( + sub map[*termRecord]*eqClass, + correspondence map[*eqClass]*termRecord, +) []Unif.Substitutions { result := Unif.MakeEmptySubstitutionList() subs := Unif.MakeEmptySubstitution() diff --git a/src/Mods/gs3/dependency.go b/src/Mods/gs3/dependency.go index 7823a9ec..93702432 100644 --- a/src/Mods/gs3/dependency.go +++ b/src/Mods/gs3/dependency.go @@ -116,7 +116,12 @@ func getAllVariableOccurrences(v AST.Var, form AST.Form) occurrences { return getVariableOccurrencesForm(v, form, occurrences{}, occurrence{}) } -func getVariableOccurrencesForm(v AST.Var, form AST.Form, currentOcc occurrences, path occurrence) occurrences { +func getVariableOccurrencesForm( + v AST.Var, + form AST.Form, + currentOcc occurrences, + path occurrence, +) occurrences { workingPath := make(occurrence, len(path)) copy(workingPath, path) switch f := form.(type) { @@ -155,7 +160,12 @@ func getNAryOcc(v AST.Var, currentOcc occurrences, path occurrence, fl *AST.Form return currentOcc } -func getVariableOccurrencesTerm(v AST.Var, term AST.Term, currentOcc occurrences, path occurrence) occurrences { +func getVariableOccurrencesTerm( + v AST.Var, + term AST.Term, + currentOcc occurrences, + path occurrence, +) occurrences { workingPath := make(occurrence, len(path)) copy(workingPath, path) switch t := term.(type) { diff --git a/src/Mods/gs3/proof.go b/src/Mods/gs3/proof.go index 67f86f9f..b9b066f4 100644 --- a/src/Mods/gs3/proof.go +++ b/src/Mods/gs3/proof.go @@ -155,8 +155,9 @@ func (gs GS3Proof) makeProof(proof []Search.ProofStruct) *GS3Sequent { // The last proofstep is a branching proofstep, so launch makeProof back on each child. for i, child := range proof[len(proof)-1].GetChildren() { childProof := GS3Proof{ - dependency: gs.dependency.Copy(), - branchForms: AST.NewFormList(appcp(gs.branchForms.Slice(), resultFormulas[i].Slice()...)...), + dependency: gs.dependency.Copy(), + branchForms: AST.NewFormList( + appcp(gs.branchForms.Slice(), resultFormulas[i].Slice()...)...), lastNode: nil, rulesApplied: appcp(gs.rulesApplied), betaHisto: appcp(gs.betaHisto, Glob.MakePair(i, proof[len(proof)-1].GetNodeId())), @@ -172,7 +173,10 @@ func (gs GS3Proof) makeProof(proof []Search.ProofStruct) *GS3Sequent { } // Returns a sequent and the result formulas. -func (gs *GS3Proof) makeProofOneStep(proofStep Search.ProofStruct, parent *GS3Sequent) []*AST.FormList { +func (gs *GS3Proof) makeProofOneStep( + proofStep Search.ProofStruct, + parent *GS3Sequent, +) []*AST.FormList { seq := MakeNewSequent() seq.setHypotheses(gs.branchForms) seq.nodeId = proofStep.Node_id @@ -233,7 +237,11 @@ func (gs *GS3Proof) makeProofOneStep(proofStep Search.ProofStruct, parent *GS3Se return forms } -func (gs *GS3Proof) manageGammaStep(proofStep Search.ProofStruct, rule Rule, seq *GS3Sequent) *GS3Sequent { +func (gs *GS3Proof) manageGammaStep( + proofStep Search.ProofStruct, + rule Rule, + seq *GS3Sequent, +) *GS3Sequent { // Manage gamma: add all the gammas except the result formula to the thing resultForm := proofStep.GetResultFormulas()[0].GetForms().Get(0) originForm := proofStep.GetFormula().GetForm() @@ -280,7 +288,11 @@ func getDepFromTerm(term AST.Term) Lib.List[AST.Term] { } // TODO: factorise this function to merge some steps that are similar between the two cases. -func (gs *GS3Proof) manageDeltaStep(proofStep Search.ProofStruct, rule Rule, parent *GS3Sequent) AST.Form { +func (gs *GS3Proof) manageDeltaStep( + proofStep Search.ProofStruct, + rule Rule, + parent *GS3Sequent, +) AST.Form { originForm := proofStep.GetFormula().GetForm() resultForm := proofStep.GetResultFormulas()[0].GetForms().Get(0) termGenerated := manageDeltasSkolemisations(proofStep.GetFormula().GetForm(), resultForm) @@ -309,7 +321,10 @@ func (gs *GS3Proof) manageDeltaStep(proofStep Search.ProofStruct, rule Rule, par } else { gs.lastNode.addChild(deltaSeq) } - previousRulesApplied = append(previousRulesApplied, Glob.MakePair(rule, makeProofStructFrom(originForm, resultForm, rule))) + previousRulesApplied = append( + previousRulesApplied, + Glob.MakePair(rule, makeProofStructFrom(originForm, resultForm, rule)), + ) gs.lastNode = deltaSeq gs.branchForms.Append(resultForm) subRoot, childrenIndex := gs.applyRulesBack(previousRulesApplied, rulesApplied, offsprings) @@ -385,7 +400,11 @@ func (gs GS3Proof) getFormulasDependantFromTerm(term AST.Term) (*AST.FormList, b return fs, ok } -func (gs GS3Proof) getRulesAppliedInOrder(term AST.Term, dependantForms *AST.FormList, deltaForm AST.Form) ([]Glob.Pair[Rule, Search.ProofStruct], *AST.FormList) { +func (gs GS3Proof) getRulesAppliedInOrder( + term AST.Term, + dependantForms *AST.FormList, + deltaForm AST.Form, +) ([]Glob.Pair[Rule, Search.ProofStruct], *AST.FormList) { offsprings := gs.getOffspringsOf(term) rules := []Glob.Pair[Rule, Search.ProofStruct]{} for _, rule := range gs.rulesApplied { @@ -486,7 +505,12 @@ func (gs *GS3Proof) removeRuleAppliedOn(form AST.Form) { } } -func (gs *GS3Proof) applyDeltaRule(form, result AST.Form, rule Rule, term AST.Term, nodeId int) *GS3Sequent { +func (gs *GS3Proof) applyDeltaRule( + form, result AST.Form, + rule Rule, + term AST.Term, + nodeId int, +) *GS3Sequent { seq := MakeNewSequent() seq.setHypotheses(gs.branchForms) seq.setAppliedRule(rule) @@ -496,14 +520,20 @@ func (gs *GS3Proof) applyDeltaRule(form, result AST.Form, rule Rule, term AST.Te gs.branchForms.Append(result) gs.deltaHisto = append(gs.deltaHisto, Glob.MakePair(term, Glob.MakePair(result, nodeId))) - gs.rulesApplied = append(gs.rulesApplied, Glob.MakePair(rule, makeProofStructFrom(form, result, rule))) + gs.rulesApplied = append( + gs.rulesApplied, + Glob.MakePair(rule, makeProofStructFrom(form, result, rule)), + ) seq.proof = gs.Copy() return seq } -func (gs GS3Proof) applyRulesBack(rulesApplied, rulesToApply []Glob.Pair[Rule, Search.ProofStruct], weakenedForms *AST.FormList) (*GS3Sequent, []int) { +func (gs GS3Proof) applyRulesBack( + rulesApplied, rulesToApply []Glob.Pair[Rule, Search.ProofStruct], + weakenedForms *AST.FormList, +) (*GS3Sequent, []int) { // Transform everything back to a proof struct & call makeProof on it. // We need to have the right proofstructs here: the proofstructs of the branches that is not this one // on the beta formulas. @@ -514,12 +544,16 @@ func (gs GS3Proof) applyRulesBack(rulesApplied, rulesToApply []Glob.Pair[Rule, S return gs.makeProof(proof), childrenIndex } -func (gs *GS3Proof) rebuildProof(rulesApplied, rules []Glob.Pair[Rule, Search.ProofStruct], weakenedForms *AST.FormList) ([]Search.ProofStruct, []int) { +func (gs *GS3Proof) rebuildProof( + rulesApplied, rules []Glob.Pair[Rule, Search.ProofStruct], + weakenedForms *AST.FormList, +) ([]Search.ProofStruct, []int) { rebuiltProof := make([]Search.ProofStruct, 0) childrenIndex := make([]int, 0) for i, rule := range rules { // These rules correspond to a beta-rule. - if rule.Fst == NAND || rule.Fst == NEQU || rule.Fst == EQU || rule.Fst == OR || rule.Fst == IMP { + if rule.Fst == NAND || rule.Fst == NEQU || rule.Fst == EQU || rule.Fst == OR || + rule.Fst == IMP { node := rule.Snd.Copy() currentBranchChildId := gs.getCurrentBranchChildId(node.GetNodeId()) for j := range node.Children { @@ -527,7 +561,11 @@ func (gs *GS3Proof) rebuildProof(rulesApplied, rules []Glob.Pair[Rule, Search.Pr childrenIndex = append(childrenIndex, j) if i+1 < len(rules) { var children []int - node.Children[j], children = gs.rebuildProof(rulesApplied, rules[i+1:], weakenedForms) + node.Children[j], children = gs.rebuildProof( + rulesApplied, + rules[i+1:], + weakenedForms, + ) childrenIndex = append(childrenIndex, children...) } else { node.Children[j] = make([]Search.ProofStruct, 0) @@ -557,7 +595,9 @@ func (gs GS3Proof) getCurrentBranchChildId(id int) int { return -1 } -func (gs GS3Proof) getFormsToWeaken(rulesApplied, rulesAlreadyWeakened []Glob.Pair[Rule, Search.ProofStruct]) *AST.FormList { +func (gs GS3Proof) getFormsToWeaken( + rulesApplied, rulesAlreadyWeakened []Glob.Pair[Rule, Search.ProofStruct], +) *AST.FormList { formsToWeaken := AST.NewFormList() rule := getFirstRuleAppliedAfter(gs.rulesApplied, rulesAlreadyWeakened[0]) canBeAppending := false @@ -567,14 +607,19 @@ func (gs GS3Proof) getFormsToWeaken(rulesApplied, rulesAlreadyWeakened []Glob.Pa } if canBeAppending { if !Glob.IsPreInnerSko() || !(rule.Fst == EX || rule.Fst == NALL) { - formsToWeaken.Append(gs.getIntersectionBetweenResultAndBranchForms(rule.Snd.GetResultFormulas()).Slice()...) + formsToWeaken.Append( + gs.getIntersectionBetweenResultAndBranchForms(rule.Snd.GetResultFormulas()). + Slice()...) } } } return formsToWeaken } -func getFirstRuleAppliedAfter(rulesApplied []Glob.Pair[Rule, Search.ProofStruct], firstRuleWeakened Glob.Pair[Rule, Search.ProofStruct]) Glob.Pair[Rule, Search.ProofStruct] { +func getFirstRuleAppliedAfter( + rulesApplied []Glob.Pair[Rule, Search.ProofStruct], + firstRuleWeakened Glob.Pair[Rule, Search.ProofStruct], +) Glob.Pair[Rule, Search.ProofStruct] { for i, rule := range rulesApplied { if equalRulePair(rule, firstRuleWeakened) && i < len(rulesApplied) { return rulesApplied[i+1] @@ -583,7 +628,9 @@ func getFirstRuleAppliedAfter(rulesApplied []Glob.Pair[Rule, Search.ProofStruct] return Glob.Pair[Rule, Search.ProofStruct]{} } -func (gs GS3Proof) getIntersectionBetweenResultAndBranchForms(forms []Search.IntFormAndTermsList) *AST.FormList { +func (gs GS3Proof) getIntersectionBetweenResultAndBranchForms( + forms []Search.IntFormAndTermsList, +) *AST.FormList { fs := AST.NewFormList() for _, fl := range forms { for _, f := range fl.GetForms().Slice() { @@ -685,7 +732,9 @@ func (gs *GS3Proof) removeFromDeltaHisto(term AST.Term) { } } -func (gs *GS3Proof) weakenAllFormsRelatedToTheTerm(term AST.Term) (*AST.FormList, []Glob.Pair[Rule, Search.ProofStruct]) { +func (gs *GS3Proof) weakenAllFormsRelatedToTheTerm( + term AST.Term, +) (*AST.FormList, []Glob.Pair[Rule, Search.ProofStruct]) { rules := []Glob.Pair[Rule, Search.ProofStruct]{} forms := AST.NewFormList() for _, form := range gs.branchForms.Slice() { diff --git a/src/Mods/lambdapi/context.go b/src/Mods/lambdapi/context.go index e9496c46..b5f33003 100644 --- a/src/Mods/lambdapi/context.go +++ b/src/Mods/lambdapi/context.go @@ -268,7 +268,16 @@ func getContextFromTerm(trm AST.Term) []string { } } - result = append(result, mapDefault(fmt.Sprintf("symbol %s : %s;", fun.GetID().ToMappedString(lambdaPiMapConnectors, false), typesStr))) + result = append( + result, + mapDefault( + fmt.Sprintf( + "symbol %s : %s;", + fun.GetID().ToMappedString(lambdaPiMapConnectors, false), + typesStr, + ), + ), + ) for _, term := range fun.GetArgs().GetSlice() { result = append(result, clean(result, getContextFromTerm(term))...) } diff --git a/src/Mods/lambdapi/formDecorator.go b/src/Mods/lambdapi/formDecorator.go index 9838a873..3ec0c7cb 100644 --- a/src/Mods/lambdapi/formDecorator.go +++ b/src/Mods/lambdapi/formDecorator.go @@ -94,7 +94,10 @@ func MakeDecoratedVar(newVar AST.Var) DecoratedVar { return decorated } -func (da DecoratedVar) ToMappedStringChild(mapping AST.MapString, displayTypes bool) (separator, emptyValue string) { +func (da DecoratedVar) ToMappedStringChild( + mapping AST.MapString, + displayTypes bool, +) (separator, emptyValue string) { emptyValue = getFromContext(da.Var) return "", emptyValue } @@ -112,7 +115,10 @@ func MakeDecoratedPred(newPred AST.Pred) DecoratedPred { return decorated } -func (dp DecoratedPred) ToMappedStringChild(mapping AST.MapString, displayTypes bool) (separator, emptyValue string) { +func (dp DecoratedPred) ToMappedStringChild( + mapping AST.MapString, + displayTypes bool, +) (separator, emptyValue string) { _, emptyValue = dp.Pred.ToMappedStringChild(mapping, displayTypes) return " ", emptyValue } @@ -130,7 +136,10 @@ func MakeDecoratedFun(newFun AST.Fun) DecoratedFun { return decorated } -func (df DecoratedFun) ToMappedStringChild(mapping AST.MapString, displayTypes bool) (separator, emptyValue string) { +func (df DecoratedFun) ToMappedStringChild( + mapping AST.MapString, + displayTypes bool, +) (separator, emptyValue string) { return " ", mapping[AST.PredEmpty] } diff --git a/src/Mods/lambdapi/output.go b/src/Mods/lambdapi/output.go index cd5de4d0..944a89b3 100644 --- a/src/Mods/lambdapi/output.go +++ b/src/Mods/lambdapi/output.go @@ -62,7 +62,11 @@ var lambdaPiMapConnectors = map[AST.FormulaType]string{ AST.TypeVarType: "Type", } -var LambdapiOutputProofStruct = &Search.OutputProofStruct{ProofOutput: MakeLambdapiOutput, Name: "Lambdapi", Extension: ".lp"} +var LambdapiOutputProofStruct = &Search.OutputProofStruct{ + ProofOutput: MakeLambdapiOutput, + Name: "Lambdapi", + Extension: ".lp", +} // ---------------------------------------------------------------------------- // Plugin initialisation and main function to call. @@ -90,7 +94,15 @@ var MakeLambdaPiProof = func(proof *gs3.GS3Sequent, meta Lib.List[AST.Meta]) str } func mapDefault(str string) string { - result := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(str, "$i", "ι"), "$o", "Prop"), "->", "→"), "*", "→") + result := strings.ReplaceAll( + strings.ReplaceAll( + strings.ReplaceAll(strings.ReplaceAll(str, "$i", "ι"), "$o", "Prop"), + "->", + "→", + ), + "*", + "→", + ) return result } diff --git a/src/Mods/lambdapi/proof.go b/src/Mods/lambdapi/proof.go index 852a7697..d3b984be 100644 --- a/src/Mods/lambdapi/proof.go +++ b/src/Mods/lambdapi/proof.go @@ -129,7 +129,13 @@ func getPosAndNeg(target AST.Form) (pos, neg AST.Form) { return target, AST.MakerNot(target) } -func allRules(rule string, target AST.Form, composingForms *AST.FormList, nexts []*gs3.GS3Sequent, children []*AST.FormList) string { +func allRules( + rule string, + target AST.Form, + composingForms *AST.FormList, + nexts []*gs3.GS3Sequent, + children []*AST.FormList, +) string { result := rule + "\n" for _, composingForm := range composingForms.Slice() { @@ -143,7 +149,15 @@ func allRules(rule string, target AST.Form, composingForms *AST.FormList, nexts return result } -func allRulesQuantUniv(rule string, target AST.Form, composingForms *AST.FormList, nexts []*gs3.GS3Sequent, children []*AST.FormList, vars []AST.Var, termGen AST.Term) string { +func allRulesQuantUniv( + rule string, + target AST.Form, + composingForms *AST.FormList, + nexts []*gs3.GS3Sequent, + children []*AST.FormList, + vars []AST.Var, + termGen AST.Term, +) string { quant := "" typeStr := vars[0].GetTypeApp().ToString() @@ -163,7 +177,10 @@ func allRulesQuantUniv(rule string, target AST.Form, composingForms *AST.FormLis varStrs := []string{} for _, singleVar := range vars { - varStrs = append(varStrs, toLambdaIntroString(singleVar, singleVar.GetTypeHint().ToString())) + varStrs = append( + varStrs, + toLambdaIntroString(singleVar, singleVar.GetTypeHint().ToString()), + ) } result = fmt.Sprintf(result, strings.Join(varStrs, ", "+quant+" ")) @@ -189,7 +206,15 @@ func getRecursionUnivStr(nexts []*gs3.GS3Sequent, children []*AST.FormList) (res return result } -func allRulesQuantExist(rule string, target AST.Form, composingForms *AST.FormList, nexts []*gs3.GS3Sequent, children []*AST.FormList, vars []AST.Var, termGen AST.Term) string { +func allRulesQuantExist( + rule string, + target AST.Form, + composingForms *AST.FormList, + nexts []*gs3.GS3Sequent, + children []*AST.FormList, + vars []AST.Var, + termGen AST.Term, +) string { quant := "" typeStr := vars[0].GetTypeApp().ToString() switch typed := target.(type) { @@ -208,7 +233,10 @@ func allRulesQuantExist(rule string, target AST.Form, composingForms *AST.FormLi varStrs := []string{} for _, singleVar := range vars { - varStrs = append(varStrs, toLambdaIntroString(singleVar, singleVar.GetTypeHint().ToString())) + varStrs = append( + varStrs, + toLambdaIntroString(singleVar, singleVar.GetTypeHint().ToString()), + ) } result = fmt.Sprintf(result, strings.Join(varStrs, ", "+quant+" ")) @@ -219,7 +247,11 @@ func allRulesQuantExist(rule string, target AST.Form, composingForms *AST.FormLi return result } -func getRecursionExistStr(nexts []*gs3.GS3Sequent, children []*AST.FormList, termGen AST.Term) (result string) { +func getRecursionExistStr( + nexts []*gs3.GS3Sequent, + children []*AST.FormList, + termGen AST.Term, +) (result string) { for i, next := range nexts { result += "(\n" typesStr := "" @@ -239,43 +271,97 @@ func getRecursionExistStr(nexts []*gs3.GS3Sequent, children []*AST.FormList, ter func alphaNotNot(proof *gs3.GS3Sequent) string { composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRules("GS3nnot", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3nnot", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func alphaAnd(proof *gs3.GS3Sequent) string { - return allRules("GS3and", proof.GetTargetForm(), proof.GetTargetForm().GetChildFormulas(), proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3and", + proof.GetTargetForm(), + proof.GetTargetForm().GetChildFormulas(), + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func alphaNotOr(proof *gs3.GS3Sequent) string { composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRules("GS3nor", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3nor", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func alphaNotImp(proof *gs3.GS3Sequent) string { composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRules("GS3nimp", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3nimp", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func betaOr(proof *gs3.GS3Sequent) string { - return allRules("GS3or", proof.GetTargetForm(), proof.GetTargetForm().GetChildFormulas(), proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3or", + proof.GetTargetForm(), + proof.GetTargetForm().GetChildFormulas(), + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func betaNotAnd(proof *gs3.GS3Sequent) string { composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRules("GS3nand", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3nand", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func betaImp(proof *gs3.GS3Sequent) string { - return allRules("GS3imp", proof.GetTargetForm(), proof.GetTargetForm().GetChildFormulas(), proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3imp", + proof.GetTargetForm(), + proof.GetTargetForm().GetChildFormulas(), + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func betaEqu(proof *gs3.GS3Sequent) string { - return allRules("GS3equ", proof.GetTargetForm(), proof.GetTargetForm().GetChildFormulas(), proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3equ", + proof.GetTargetForm(), + proof.GetTargetForm().GetChildFormulas(), + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func betaNotEqu(proof *gs3.GS3Sequent) string { composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRules("GS3nequ", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren()) + return allRules( + "GS3nequ", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + ) } func deltaEx(proof *gs3.GS3Sequent) string { @@ -284,7 +370,15 @@ func deltaEx(proof *gs3.GS3Sequent) string { formulaEx = form } - return allRulesQuantExist("GS3ex", proof.GetTargetForm(), proof.GetTargetForm().GetChildFormulas(), proof.Children(), proof.GetResultFormulasOfChildren(), formulaEx.GetVarList(), proof.TermGenerated()) + return allRulesQuantExist( + "GS3ex", + proof.GetTargetForm(), + proof.GetTargetForm().GetChildFormulas(), + proof.Children(), + proof.GetResultFormulasOfChildren(), + formulaEx.GetVarList(), + proof.TermGenerated(), + ) } func deltaNotAll(proof *gs3.GS3Sequent) string { @@ -296,7 +390,15 @@ func deltaNotAll(proof *gs3.GS3Sequent) string { } composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRulesQuantExist("GS3nall", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren(), formulaAll.GetVarList(), proof.TermGenerated()) + return allRulesQuantExist( + "GS3nall", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + formulaAll.GetVarList(), + proof.TermGenerated(), + ) } func gammaAll(proof *gs3.GS3Sequent) string { @@ -305,7 +407,15 @@ func gammaAll(proof *gs3.GS3Sequent) string { formulaAll = form } - return allRulesQuantUniv("GS3all", proof.GetTargetForm(), proof.GetTargetForm().GetChildFormulas(), proof.Children(), proof.GetResultFormulasOfChildren(), formulaAll.GetVarList(), proof.TermGenerated()) + return allRulesQuantUniv( + "GS3all", + proof.GetTargetForm(), + proof.GetTargetForm().GetChildFormulas(), + proof.Children(), + proof.GetResultFormulasOfChildren(), + formulaAll.GetVarList(), + proof.TermGenerated(), + ) } func gammaNotEx(proof *gs3.GS3Sequent) string { @@ -317,7 +427,15 @@ func gammaNotEx(proof *gs3.GS3Sequent) string { } composingForms := proof.GetTargetForm().GetChildFormulas().Get(0).GetChildFormulas() - return allRulesQuantUniv("GS3nex", proof.GetTargetForm(), composingForms, proof.Children(), proof.GetResultFormulasOfChildren(), formulaEx.GetVarList(), proof.TermGenerated()) + return allRulesQuantUniv( + "GS3nex", + proof.GetTargetForm(), + composingForms, + proof.Children(), + proof.GetResultFormulasOfChildren(), + formulaEx.GetVarList(), + proof.TermGenerated(), + ) } // Processes the formula that was proven by Goéland. @@ -336,11 +454,17 @@ func processMainFormula(form AST.Form) (*AST.FormList, AST.Form) { // Prints the theorem's name & properly formats the first formula. func makeTheorem(axioms *AST.FormList, conjecture AST.Form) string { - problemName := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(Glob.GetProblemName(), ".", "_"), "=", "_"), "+", "_") + problemName := strings.ReplaceAll( + strings.ReplaceAll(strings.ReplaceAll(Glob.GetProblemName(), ".", "_"), "=", "_"), + "+", + "_", + ) axioms = axioms.Copy() axioms.Append(AST.MakerNot(conjecture)) formattedProblem := makeImpChain(axioms) - return "symbol goeland_" + problemName + " : \nϵ " + toCorrectString(formattedProblem) + " → ϵ ⊥ ≔ \n" + return "symbol goeland_" + problemName + " : \nϵ " + toCorrectString( + formattedProblem, + ) + " → ϵ ⊥ ≔ \n" } // If [F1, F2, F3] is a formlist, then this function returns F1 -> (F2 -> F3). diff --git a/src/Mods/rocq/output.go b/src/Mods/rocq/output.go index 1efaaff6..e351cddb 100644 --- a/src/Mods/rocq/output.go +++ b/src/Mods/rocq/output.go @@ -48,7 +48,11 @@ import ( var contextEnabled bool = false -var RocqOutputProofStruct = &Search.OutputProofStruct{ProofOutput: MakeRocqOutput, Name: "Rocq", Extension: ".v"} +var RocqOutputProofStruct = &Search.OutputProofStruct{ + ProofOutput: MakeRocqOutput, + Name: "Rocq", + Extension: ".v", +} // ---------------------------------------------------------------------------- // Plugin initialisation and main function to call. diff --git a/src/Mods/rocq/proof.go b/src/Mods/rocq/proof.go index e9beda52..2907f19a 100644 --- a/src/Mods/rocq/proof.go +++ b/src/Mods/rocq/proof.go @@ -64,7 +64,10 @@ func makeRocqProofFromGS3(proof *gs3.GS3Sequent) string { for i, form := range axioms.Slice() { indices[i], hypotheses = introduce(form, hypotheses) } - resultingString += "intros " + strings.Join(Glob.MapTo(indices, func(_ int, index int) string { return introName(index) }), " ") + ". " + resultingString += "intros " + strings.Join( + Glob.MapTo(indices, func(_ int, index int) string { return introName(index) }), + " ", + ) + ". " if totalAxioms > 0 { proof = proof.Child(0) } @@ -76,15 +79,27 @@ func makeRocqProofFromGS3(proof *gs3.GS3Sequent) string { return resultingString + "\nQed.\n" } -func followProofSteps(proof *gs3.GS3Sequent, hypotheses *AST.FormList, constantsCreated []AST.Term) string { +func followProofSteps( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + constantsCreated []AST.Term, +) string { var resultingString string var childrenHypotheses []*AST.FormList if !proof.IsEmpty() { - resultingString, childrenHypotheses, constantsCreated = makeProofStep(proof, hypotheses, constantsCreated) + resultingString, childrenHypotheses, constantsCreated = makeProofStep( + proof, + hypotheses, + constantsCreated, + ) } for i, child := range proof.Children() { if proof.IsEmpty() { - resultingString += "\n" + followProofSteps(child, hypotheses.Copy(), cp(constantsCreated)) + resultingString += "\n" + followProofSteps( + child, + hypotheses.Copy(), + cp(constantsCreated), + ) } else { resultingString += "\n" + followProofSteps(child, childrenHypotheses[i].Copy(), cp(constantsCreated)) } @@ -92,12 +107,24 @@ func followProofSteps(proof *gs3.GS3Sequent, hypotheses *AST.FormList, constants return resultingString } -func makeProofStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, constantsCreated []AST.Term) (string, []*AST.FormList, []AST.Term) { - stepResult, childrenHypotheses, constantsCreated := makeStep(proof, hypotheses, constantsCreated) +func makeProofStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + constantsCreated []AST.Term, +) (string, []*AST.FormList, []AST.Term) { + stepResult, childrenHypotheses, constantsCreated := makeStep( + proof, + hypotheses, + constantsCreated, + ) return stepResult, childrenHypotheses, constantsCreated } -func makeStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, constantsCreated []AST.Term) (string, []*AST.FormList, []AST.Term) { +func makeStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + constantsCreated []AST.Term, +) (string, []*AST.FormList, []AST.Term) { var resultingString string childrenHypotheses := []*AST.FormList{hypotheses} @@ -115,59 +142,145 @@ func makeStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, constantsCreated case gs3.NNOT: resultingString, childrenHypotheses = alphaStep(proof, hypotheses, target, "%s") case gs3.AND: - resultingString, childrenHypotheses = alphaStep(proof, hypotheses, target, "(goeland_and_s _ _ %s)") + resultingString, childrenHypotheses = alphaStep( + proof, + hypotheses, + target, + "(goeland_and_s _ _ %s)", + ) case gs3.NOR: - resultingString, childrenHypotheses = alphaStep(proof, hypotheses, target, "(goeland_notor_s _ _ %s)") + resultingString, childrenHypotheses = alphaStep( + proof, + hypotheses, + target, + "(goeland_notor_s _ _ %s)", + ) case gs3.NIMP: - resultingString, childrenHypotheses = alphaStep(proof, hypotheses, target, "(goeland_notimply_s _ _ %s)") + resultingString, childrenHypotheses = alphaStep( + proof, + hypotheses, + target, + "(goeland_notimply_s _ _ %s)", + ) // Beta rules case gs3.NAND: - resultingString, childrenHypotheses = betaStep(proof, hypotheses, target, "(goeland_notand_s _ _ %s)") + resultingString, childrenHypotheses = betaStep( + proof, + hypotheses, + target, + "(goeland_notand_s _ _ %s)", + ) case gs3.NEQU: - resultingString, childrenHypotheses = betaStep(proof, hypotheses, target, "(goeland_notequiv_s _ _ %s)") + resultingString, childrenHypotheses = betaStep( + proof, + hypotheses, + target, + "(goeland_notequiv_s _ _ %s)", + ) case gs3.OR: - resultingString, childrenHypotheses = betaStep(proof, hypotheses, target, "(goeland_or_s _ _ %s)") + resultingString, childrenHypotheses = betaStep( + proof, + hypotheses, + target, + "(goeland_or_s _ _ %s)", + ) case gs3.IMP: - resultingString, childrenHypotheses = betaStep(proof, hypotheses, target, "(goeland_imply_s _ _ %s)") + resultingString, childrenHypotheses = betaStep( + proof, + hypotheses, + target, + "(goeland_imply_s _ _ %s)", + ) case gs3.EQU: - resultingString, childrenHypotheses = betaStep(proof, hypotheses, target, "(goeland_equiv_s _ _ %s)") + resultingString, childrenHypotheses = betaStep( + proof, + hypotheses, + target, + "(goeland_equiv_s _ _ %s)", + ) // Delta rules case gs3.NALL: - resultingString, childrenHypotheses, constantsCreated = deltaStep(proof, hypotheses, target, "apply %s. intros %s. apply NNPP. intros %s. ", constantsCreated) + resultingString, childrenHypotheses, constantsCreated = deltaStep( + proof, + hypotheses, + target, + "apply %s. intros %s. apply NNPP. intros %s. ", + constantsCreated, + ) case gs3.EX: - resultingString, childrenHypotheses, constantsCreated = deltaStep(proof, hypotheses, target, "elim %s. intros %s. intros %s. ", constantsCreated) + resultingString, childrenHypotheses, constantsCreated = deltaStep( + proof, + hypotheses, + target, + "elim %s. intros %s. intros %s. ", + constantsCreated, + ) // Gamma rules case gs3.ALL: - resultingString, childrenHypotheses = gammaStep(proof, hypotheses, target, "generalize (%s %s). intros %s. ", constantsCreated) + resultingString, childrenHypotheses = gammaStep( + proof, + hypotheses, + target, + "generalize (%s %s). intros %s. ", + constantsCreated, + ) case gs3.NEX: - resultingString, childrenHypotheses = gammaStep(proof, hypotheses, target, "apply %s. exists %s. apply NNPP. intros %s. ", constantsCreated) + resultingString, childrenHypotheses = gammaStep( + proof, + hypotheses, + target, + "apply %s. exists %s. apply NNPP. intros %s. ", + constantsCreated, + ) // Weakening rule case gs3.W: if proof.TermGenerated() != nil { - resultingString = fmt.Sprintf("clear %s.", getConstantName(proof.TermGenerated().(AST.Fun).GetID())) + resultingString = fmt.Sprintf( + "clear %s.", + getConstantName(proof.TermGenerated().(AST.Fun).GetID()), + ) } else { resultingString, childrenHypotheses = cleanHypotheses(hypotheses, proof.GetTargetForm()) } case gs3.REWRITE: - resultingString, childrenHypotheses = rewriteStep(proof.GetRewriteWith(), hypotheses, target, proof.GetResultFormulasOfChild(0).Get(0)) + resultingString, childrenHypotheses = rewriteStep( + proof.GetRewriteWith(), + hypotheses, + target, + proof.GetResultFormulasOfChild(0).Get(0), + ) } return resultingString, childrenHypotheses, constantsCreated } -func alphaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList) { +func alphaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList) { var indices []int indices, hypotheses = introduceList(proof.GetResultFormulasOfChild(0), hypotheses) - resultingString := fmt.Sprintf("apply "+format+". intros %s. ", introName(target), introNames(indices)) + resultingString := fmt.Sprintf( + "apply "+format+". intros %s. ", + introName(target), + introNames(indices), + ) return resultingString, []*AST.FormList{hypotheses} } -func betaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList) { +func betaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList) { resultHyps := []*AST.FormList{} var indices []int resultingString := fmt.Sprintf("apply "+format+"; ", introName(target)) @@ -182,7 +295,13 @@ func betaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, forma return resultingString + "[ " + strings.Join(introducedNames, " | ") + " ].", resultHyps } -func deltaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string, constantsCreated []AST.Term) (string, []*AST.FormList, []AST.Term) { +func deltaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, + constantsCreated []AST.Term, +) (string, []*AST.FormList, []AST.Term) { var indices []int var name string //PrintInfo("DELTA", fmt.Sprintf("%s\n%s", hypotheses[target].ToString(), proof.GetResultFormulasOfChild(0).ToString())) @@ -192,7 +311,13 @@ func deltaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form return resultingString, []*AST.FormList{hypotheses}, constantsCreated } -func gammaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string, constantsCreated []AST.Term) (string, []*AST.FormList) { +func gammaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, + constantsCreated []AST.Term, +) (string, []*AST.FormList) { var indices []int indices, hypotheses = introduceList(proof.GetResultFormulasOfChild(0), hypotheses) name := "(" + getRealConstantName(constantsCreated, proof.TermGenerated()) + ")" @@ -200,7 +325,12 @@ func gammaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form return resultingString, []*AST.FormList{hypotheses} } -func rewriteStep(rewriteRule AST.Form, hypotheses *AST.FormList, target int, replacementForm AST.Form) (string, []*AST.FormList) { +func rewriteStep( + rewriteRule AST.Form, + hypotheses *AST.FormList, + target int, + replacementForm AST.Form, +) (string, []*AST.FormList) { index, _ := hypotheses.GetIndexOf(rewriteRule) resultingString := fmt.Sprintf("rewrite %s in %s.", introName(index), introName(target)) hypotheses.Set(target, replacementForm) @@ -223,12 +353,18 @@ func processMainFormula(form AST.Form) (*AST.FormList, AST.Form) { // Prints the theorem's name & properly formats the first formula. func makeTheorem(axioms *AST.FormList, conjecture AST.Form) string { - problemName := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(Glob.GetProblemName(), ".", "_"), "=", "_"), "+", "_") + problemName := strings.ReplaceAll( + strings.ReplaceAll(strings.ReplaceAll(Glob.GetProblemName(), ".", "_"), "=", "_"), + "+", + "_", + ) axiomsWithConj := axioms.Copy() axiomsWithConj.Append(AST.MakerNot(AST.MakerNot(conjecture))) formattedProblem := makeImpChain(axiomsWithConj) return "Theorem goeland_proof_of_" + problemName + " : " + - mapDefault(formattedProblem.ToMappedString(rocqMapConnectors(), Glob.GetTypeProof())) + ".\n" + mapDefault( + formattedProblem.ToMappedString(rocqMapConnectors(), Glob.GetTypeProof()), + ) + ".\n" } // If [F1, F2, F3] is a formlist, then this function returns F1 -> (F2 -> F3). diff --git a/src/Mods/tptp/output.go b/src/Mods/tptp/output.go index ee48f084..02bef2f4 100644 --- a/src/Mods/tptp/output.go +++ b/src/Mods/tptp/output.go @@ -46,7 +46,11 @@ import ( "github.com/GoelandProver/Goeland/Search" ) -var TptpOutputProofStruct = &Search.OutputProofStruct{ProofOutput: MakeTptpOutput, Name: "TPTP", Extension: ".p"} +var TptpOutputProofStruct = &Search.OutputProofStruct{ + ProofOutput: MakeTptpOutput, + Name: "TPTP", + Extension: ".p", +} // ---------------------------------------------------------------------------- // Plugin initialisation and main function to call. @@ -78,7 +82,11 @@ var MakeTptpProof = func(proof *gs3.GS3Sequent, meta Lib.List[AST.Meta]) string // Replace defined symbols by TSTP's defined symbols. func mapDefault(str string) string { - return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(str, " : $i", ""), " : $o", ""), " : , ", " : ") + return strings.ReplaceAll( + strings.ReplaceAll(strings.ReplaceAll(str, " : $i", ""), " : $o", ""), + " : , ", + " : ", + ) } func tptpMapConnectors() map[AST.FormulaType]string { return map[AST.FormulaType]string{ diff --git a/src/Mods/tptp/proof.go b/src/Mods/tptp/proof.go index 83475561..96c0ad5f 100644 --- a/src/Mods/tptp/proof.go +++ b/src/Mods/tptp/proof.go @@ -89,7 +89,11 @@ func followProofSteps(proof *gs3.GS3Sequent, hypotheses *AST.FormList, new_curre var resultingStringParent string var childrenHypotheses []*AST.FormList if !proof.IsEmpty() { - resultingStringParent, childrenHypotheses, new_current_id = makeProofStep(proof, hypotheses, new_current_id) + resultingStringParent, childrenHypotheses, new_current_id = makeProofStep( + proof, + hypotheses, + new_current_id, + ) } for i, child := range proof.Children() { if proof.IsEmpty() { @@ -103,8 +107,16 @@ func followProofSteps(proof *gs3.GS3Sequent, hypotheses *AST.FormList, new_curre return resultingString + resultingStringParent } -func makeProofStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, new_current_id int) (string, []*AST.FormList, int) { - stepResult, childrenHypotheses, next_child_weakened_id := makeStep(proof, hypotheses, new_current_id) +func makeProofStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + new_current_id int, +) (string, []*AST.FormList, int) { + stepResult, childrenHypotheses, next_child_weakened_id := makeStep( + proof, + hypotheses, + new_current_id, + ) return stepResult, childrenHypotheses, next_child_weakened_id } @@ -125,7 +137,11 @@ func findIndexPos(f AST.Form, hypotheses *AST.FormList, target int) int { return targetPos } -func makeStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, new_current_id int) (string, []*AST.FormList, int) { +func makeStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + new_current_id int, +) (string, []*AST.FormList, int) { var resultingString string childrenHypotheses := []*AST.FormList{hypotheses} next_child_weakened_id := -1 @@ -138,11 +154,21 @@ func makeStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, new_current_id in // Closure. case gs3.AX: if isPredEqual(proof.GetTargetForm()) { - resultingString = fmt.Sprintf("fof("+prefix_step+"%d, plain, [%s] --> [], inference(%s, [status(thm)], [%s])).", + resultingString = fmt.Sprintf( + "fof("+prefix_step+"%d, plain, [%s] --> [], inference(%s, [status(thm)], [%s])).", proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + hypotheses.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), "congruence", - "") + "", + ) } else { targetPos := findIndexPos(proof.GetTargetForm(), hypotheses, target) @@ -191,19 +217,34 @@ func makeStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, new_current_id in // Weakening rule case gs3.W: if proof.TermGenerated() != nil { - resultingString = fmt.Sprintf("leftWeaken %s", findInConstants(proof.TermGenerated()).ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())) + resultingString = fmt.Sprintf( + "leftWeaken %s", + findInConstants( + proof.TermGenerated(), + ).ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), + ) } else { resultingString, childrenHypotheses, next_child_weakened_id = weakenStep(proof, hypotheses, target, "leftWeaken") } case gs3.REWRITE: - resultingString, childrenHypotheses = rewriteStep(proof.GetRewriteWith(), hypotheses, target, proof.GetResultFormulasOfChild(0).Get(0)) + resultingString, childrenHypotheses = rewriteStep( + proof.GetRewriteWith(), + hypotheses, + target, + proof.GetResultFormulasOfChild(0).Get(0), + ) } return resultingString + "\n", childrenHypotheses, next_child_weakened_id } -func alphaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList) { +func alphaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList) { children_id := []int{} for _, c := range proof.Children() { @@ -212,20 +253,35 @@ func alphaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form c.SetId(new_id) } - resultingString := fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).", + resultingString := fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).", prefix_step, proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + hypotheses.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), format, target, - Glob.IntListToString(children_id, prefix_step)) + Glob.IntListToString(children_id, prefix_step), + ) newHypotheses := hypotheses.Copy() newHypotheses.AppendIfNotContains(proof.GetResultFormulasOfChild(0).Slice()...) return resultingString, []*AST.FormList{newHypotheses} } -func betaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList) { +func betaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList) { resultHyps := []*AST.FormList{} children_id := []int{} @@ -238,18 +294,27 @@ func betaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, forma resultHyps = append(resultHyps, newHypotheses) } - resultingString := fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).", + resultingString := fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).", prefix_step, proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), false)), + mapDefault( + AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), false), + ), format, target, - Glob.IntListToString(children_id, prefix_step)) + Glob.IntListToString(children_id, prefix_step), + ) return resultingString, resultHyps } -func deltaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList) { +func deltaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList) { children_id := []int{} for _, c := range proof.Children() { new_id := incrByOne(&id_proof_step, &mutex_proof_step) @@ -258,17 +323,27 @@ func deltaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form } new_term := createNewConstant(proof.TermGenerated()) - + proof = updateSkolemSymbol(proof.TermGenerated(), new_term, proof) - resultingString := fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d, '%s'], [%s])).", + resultingString := fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d, '%s'], [%s])).", prefix_step, proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + hypotheses.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), format, target, new_term.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), - Glob.IntListToString(children_id, prefix_step)) + Glob.IntListToString(children_id, prefix_step), + ) newHypotheses := hypotheses.Copy() newHypotheses.AppendIfNotContains(proof.GetResultFormulasOfChild(0).Slice()...) @@ -276,7 +351,12 @@ func deltaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form return resultingString, []*AST.FormList{newHypotheses} } -func gammaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList) { +func gammaStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList) { children_id := []int{} for _, c := range proof.Children() { new_id := incrByOne(&id_proof_step, &mutex_proof_step) @@ -286,14 +366,26 @@ func gammaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form get(proof.GetTargetForm(), hypotheses) - resultingString := fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d, $fot(%s)], [%s])).", + resultingString := fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d, $fot(%s)], [%s])).", prefix_step, proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + hypotheses.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), format, target, - findInConstants(proof.TermGenerated()).ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), - Glob.IntListToString(children_id, prefix_step)) + findInConstants( + proof.TermGenerated(), + ).ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), + Glob.IntListToString(children_id, prefix_step), + ) newHypotheses := hypotheses.Copy() newHypotheses.AppendIfNotContains(proof.GetResultFormulasOfChild(0).Slice()...) @@ -301,33 +393,51 @@ func gammaStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, form return resultingString, []*AST.FormList{newHypotheses} } -func weakenStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int, format string) (string, []*AST.FormList, int) { +func weakenStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, + format string, +) (string, []*AST.FormList, int) { child_id := incrByOne(&id_proof_step, &mutex_proof_step) if target != -1 { hypotheses.Remove(target) } - resultingString := fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d])).", + resultingString := fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d])).", prefix_step, proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), false)), + mapDefault( + AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), false), + ), format, target, prefix_step, - child_id) + child_id, + ) return resultingString, []*AST.FormList{hypotheses}, child_id } -func rewriteStep(rewriteRule AST.Form, hypotheses *AST.FormList, target int, replacementForm AST.Form) (string, []*AST.FormList) { +func rewriteStep( + rewriteRule AST.Form, + hypotheses *AST.FormList, + target int, + replacementForm AST.Form, +) (string, []*AST.FormList) { // resultingString := fmt.Sprintf("rewrite %s in %s.", introName(get(rewriteRule, hypotheses)), introName(target)) // hypotheses[target] = replacementForm // return resultingString, []*AST.FormList{hypotheses} return "", []*AST.FormList{} } -func EquStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int) (string, []*AST.FormList) { +func EquStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, +) (string, []*AST.FormList) { resultingString := "" resultHyps := []*AST.FormList{} children_id := []int{} @@ -351,82 +461,145 @@ func EquStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int) (strin // from A <=> B to A => B, B => A (unary) s1_id := fmt.Sprintf("%s%dext1", prefix_step, proof.GetId()) - resultingString = fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).", - prefix_step, - proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftIff", - target, - s1_id) + resultingString + resultingString = fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).", + prefix_step, + proof.GetId(), + mapDefault( + AST.ListToMappedString( + hypotheses.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftIff", + target, + s1_id, + ) + resultingString // from A => B, B => A to ~A, B => A | B, B => A (binary) s2_id := fmt.Sprintf("%s%dext2", prefix_step, proof.GetId()) s3_id := fmt.Sprintf("%s%dext3", prefix_step, proof.GetId()) newHyp := hypotheses.Copy() newHyp.AppendIfNotContains([]AST.Form{A_imp_B, B_imp_A}...) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s, %s])).\n\n", - s1_id, - mapDefault(AST.ListToMappedString(newHyp.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftImp2", - get(A_imp_B, newHyp), - s2_id, - s3_id) + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s, %s])).\n\n", + s1_id, + mapDefault( + AST.ListToMappedString( + newHyp.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftImp2", + get(A_imp_B, newHyp), + s2_id, + s3_id, + ) + resultingString // Branch s2 : from ~A, B => A to ~A, ~B | ~A, A s2_closure_id := fmt.Sprintf("%sext1", s2_id) newHypS2 := newHyp.Copy() newHypS2.AppendIfNotContains(notA) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d, %s])).\n\n", - s2_id, - mapDefault(AST.ListToMappedString(newHypS2.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftImp2", - get(B_imp_A, newHypS2), - prefix_step, - children_id[0], - s2_closure_id) + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d, %s])).\n\n", + s2_id, + mapDefault( + AST.ListToMappedString( + newHypS2.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftImp2", + get(B_imp_A, newHypS2), + prefix_step, + children_id[0], + s2_closure_id, + ) + resultingString resultHyps[0].AppendIfNotContains(newHypS2.Slice()...) - // Branch 2.closure : from ~A, A closure - check polarity before newHypS2Closure := newHypS2.Copy() newHypS2Closure.AppendIfNotContains(A) targetPosS2 := findIndexPos(A, newHypS2Closure, get(A, newHypS2Closure)) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).\n\n", - s2_closure_id, - mapDefault(AST.ListToMappedString(newHypS2Closure.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftHyp", - targetPosS2, - "") + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).\n\n", + s2_closure_id, + mapDefault( + AST.ListToMappedString( + newHypS2Closure.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftHyp", + targetPosS2, + "", + ) + resultingString // Branch s3: from B, B => A to B, ~B | B, A s3_closure_id := fmt.Sprintf("%sext1", s3_id) newHypS3 := newHyp.Copy() newHypS3.AppendIfNotContains(B) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s, %s%d])).\n\n", - s3_id, - mapDefault(AST.ListToMappedString(newHypS3.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftImp2", - get(B_imp_A, newHypS3), - s3_closure_id, - prefix_step, - children_id[1]) + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s, %s%d])).\n\n", + s3_id, + mapDefault( + AST.ListToMappedString( + newHypS3.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftImp2", + get(B_imp_A, newHypS3), + s3_closure_id, + prefix_step, + children_id[1], + ) + resultingString resultHyps[1].AppendIfNotContains(newHypS3.Slice()...) // Branch 3.closure : from B, ~B closure - check polarity before newHypS3Closure := newHypS3.Copy() newHypS3Closure.AppendIfNotContains(notB) targetPosS3 := findIndexPos(B, newHypS3Closure, get(B, newHypS3Closure)) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).\n\n", - s3_closure_id, - mapDefault(AST.ListToMappedString(newHypS3Closure.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftHyp", - targetPosS3, - "") + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s])).\n\n", + s3_closure_id, + mapDefault( + AST.ListToMappedString( + newHypS3Closure.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftHyp", + targetPosS3, + "", + ) + resultingString return resultingString, resultHyps } -func NotEquStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int) (string, []*AST.FormList) { +func NotEquStep( + proof *gs3.GS3Sequent, + hypotheses *AST.FormList, + target int, +) (string, []*AST.FormList) { resultingString := "" resultHyps := []*AST.FormList{} children_id := []int{} @@ -450,43 +623,72 @@ func NotEquStep(proof *gs3.GS3Sequent, hypotheses *AST.FormList, target int) (st // from ~(A <=> B) to ~(A => B) | ~(B => A) (binary) s1_id := fmt.Sprintf("%s%dext1", prefix_step, proof.GetId()) s2_id := fmt.Sprintf("%s%dext2", prefix_step, proof.GetId()) - resultingString = fmt.Sprintf("fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s, %s])).", - prefix_step, - proof.GetId(), - mapDefault(AST.ListToMappedString(hypotheses.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftNotIff", - target, - s1_id, - s2_id) + resultingString + resultingString = fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s, %s])).", + prefix_step, + proof.GetId(), + mapDefault( + AST.ListToMappedString( + hypotheses.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftNotIff", + target, + s1_id, + s2_id, + ) + resultingString // from ~(A => B) to A, ~B newHyp1 := hypotheses.Copy() newHyp1.AppendIfNotContains(not_A_imp_B) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d])).\n\n", - s1_id, - mapDefault(AST.ListToMappedString(newHyp1.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftNotImplies", - get(not_A_imp_B, newHyp1), - prefix_step, - children_id[1]) + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d])).\n\n", + s1_id, + mapDefault( + AST.ListToMappedString( + newHyp1.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftNotImplies", + get(not_A_imp_B, newHyp1), + prefix_step, + children_id[1], + ) + resultingString resultHyps[1].AppendIfNotContains(newHyp1.Slice()...) // from ~(B => A) to B, ~A newHyp2 := hypotheses.Copy() newHyp2.AppendIfNotContains(not_B_imp_A) - resultingString = fmt.Sprintf("fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d])).\n\n", - s2_id, - mapDefault(AST.ListToMappedString(newHyp2.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), - "leftNotImplies", - get(not_B_imp_A, newHyp2), - prefix_step, - children_id[0]) + resultingString + resultingString = fmt.Sprintf( + "fof(%s, plain, [%s] --> [], inference(%s, [status(thm), %d], [%s%d])).\n\n", + s2_id, + mapDefault( + AST.ListToMappedString( + newHyp2.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), + "leftNotImplies", + get(not_B_imp_A, newHyp2), + prefix_step, + children_id[0], + ) + resultingString resultHyps[0].AppendIfNotContains(newHyp2.Slice()...) return resultingString, resultHyps } - /*** Initial Formula Management ***/ // Processes the formula that was proven by Goéland. @@ -506,59 +708,106 @@ func processMainFormula(form AST.Form) (*AST.FormList, AST.Form) { // Prints the theorem's name & properly formats the first formula. func makeTheorem(axioms *AST.FormList, conjecture AST.Form) string { var resulting_string string - problemName := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(Glob.GetProblemName(), ".", "_"), "=", "_"), "+", "_") + problemName := strings.ReplaceAll( + strings.ReplaceAll(strings.ReplaceAll(Glob.GetProblemName(), ".", "_"), "=", "_"), + "+", + "_", + ) for _, ax := range axioms.Slice() { - resulting_string = resulting_string + "fof(" + fmt.Sprintf("ax%d", ax.GetIndex()) + ", axiom, " + mapDefault(ax.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())) + ").\n\n" + resulting_string = resulting_string + "fof(" + fmt.Sprintf( + "ax%d", + ax.GetIndex(), + ) + ", axiom, " + mapDefault( + ax.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), + ) + ").\n\n" } - resulting_string = resulting_string + "fof(c_" + problemName + ", conjecture, " + mapDefault(conjecture.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())) + ").\n\n" + resulting_string = resulting_string + "fof(c_" + problemName + ", conjecture, " + mapDefault( + conjecture.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), + ) + ").\n\n" return resulting_string } // Perform the first step to go from ax |- c to ax, ~c |- -func performFirstStep(axioms *AST.FormList, conjecture AST.Form, hypothesis *AST.FormList, nextId int) (string, int) { +func performFirstStep( + axioms *AST.FormList, + conjecture AST.Form, + hypothesis *AST.FormList, + nextId int, +) (string, int) { cutFormNotId := incrByOne(&id_proof_step, &mutex_proof_step) cutFormHypId := incrByOne(&id_proof_step, &mutex_proof_step) nextFormId := incrByOne(&id_proof_step, &mutex_proof_step) // Cut initial formula, |- ~c, c step - cutFormNot := fmt.Sprintf("fof("+prefix_step+"%d, plain, [%s] --> [%s, %s], inference(%s, [status(thm), %d], [%s])).", + cutFormNot := fmt.Sprintf( + "fof("+prefix_step+"%d, plain, [%s] --> [%s, %s], inference(%s, [status(thm), %d], [%s])).", cutFormNotId, - mapDefault(AST.ListToMappedString(axioms.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + axioms.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), mapDefault(conjecture.ToMappedString(tptpMapConnectors(), false)), - mapDefault(AST.MakerNot(conjecture).ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.MakerNot(conjecture).ToMappedString(tptpMapConnectors(), Glob.GetTypeProof()), + ), "rightNot", 1, - prefix_step+strconv.Itoa(cutFormHypId)) + prefix_step+strconv.Itoa(cutFormHypId), + ) // Cut initial formula, c |- c step - cutFormHyp := fmt.Sprintf("fof("+prefix_step+"%d, plain, [%s] --> [%s], inference(%s, [status(thm), %d], [%s])).", + cutFormHyp := fmt.Sprintf( + "fof("+prefix_step+"%d, plain, [%s] --> [%s], inference(%s, [status(thm), %d], [%s])).", cutFormHypId, - mapDefault(AST.ListToMappedString(append(axioms.Slice(), conjecture), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + append(axioms.Slice(), conjecture), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), mapDefault(conjecture.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())), "hyp", axioms.Len(), // 0, - "") + "", + ) // Actual start of the formula with H |- C // indexHyp, _ := hypothesis.GetIndexOf(AST.MakerNot(conjecture)) - startForm := fmt.Sprintf("fof(f%d, plain, [%s] --> [%s], inference(cut, [status(thm), %d], [%s%d, %s%d])).\n\n", + startForm := fmt.Sprintf( + "fof(f%d, plain, [%s] --> [%s], inference(cut, [status(thm), %d], [%s%d, %s%d])).\n\n", nextId, - mapDefault(AST.ListToMappedString(axioms.Slice(), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + axioms.Slice(), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), mapDefault(conjecture.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())), 1, //indexHyp, prefix_step, cutFormNotId, prefix_step, - nextFormId) + nextFormId, + ) return cutFormHyp + "\n\n" + cutFormNot + "\n\n" + startForm, nextFormId } - // Perform the cut axiom steps func performCutAxiomStep(axioms *AST.FormList, conjecture AST.Form) string { @@ -573,17 +822,27 @@ func performCutAxiomStep(axioms *AST.FormList, conjecture AST.Form) string { nextStep = prefix_axiom_cut + strconv.Itoa(i+1) } - cutAxiomStep := fmt.Sprintf("fof(%s%d, plain, [%s] --> [%s], inference(cut, [status(thm), %d], [%s%d, %s])).\n", + cutAxiomStep := fmt.Sprintf( + "fof(%s%d, plain, [%s] --> [%s], inference(cut, [status(thm), %d], [%s%d, %s])).\n", prefix_axiom_cut, i, // AST.ListToMappedString(axioms.GetElements(0, i), ", ", "", tptpMapConnectors(), GetTypeProof()), - mapDefault(AST.ListToMappedString(axioms.GetElements(0, i), ", ", "", tptpMapConnectors(), Glob.GetTypeProof())), + mapDefault( + AST.ListToMappedString( + axioms.GetElements(0, i), + ", ", + "", + tptpMapConnectors(), + Glob.GetTypeProof(), + ), + ), mapDefault(conjecture.ToMappedString(tptpMapConnectors(), Glob.GetTypeProof())), 0, //i, "ax", ax.GetIndex(), - nextStep) + nextStep, + ) resultString = cutAxiomStep + "\n" + resultString } @@ -646,7 +905,7 @@ func updateSkolemSymbol(old, new AST.Term, proof *gs3.GS3Sequent) *gs3.GS3Sequen new_forms_generated_bis.Append(new_term) } new_forms_generated[i] = new_forms_generated_bis - } + } proof.SetFormGenerated(new_forms_generated) // Update Children @@ -666,7 +925,7 @@ func createNewConstant(term AST.Term) AST.Term { mutex_constant.Lock() new_id := len(constant_created) new_term_name := fmt.Sprintf("%s%d", prefix_const, new_id) - new_term := AST .MakerConst(AST.MakerNewId(new_term_name)) + new_term := AST.MakerConst(AST.MakerNewId(new_term_name)) original_term = append(original_term, term) constant_created = append(constant_created, new_term) mutex_constant.Unlock() diff --git a/src/Parser/pprinter.go b/src/Parser/pprinter.go index b8233333..559d8bfa 100644 --- a/src/Parser/pprinter.go +++ b/src/Parser/pprinter.go @@ -36,6 +36,7 @@ package Parser import ( "fmt" + "github.com/GoelandProver/Goeland/Lib" ) diff --git a/src/Parser/psyntax.go b/src/Parser/psyntax.go index 8fd2dde8..d04d9908 100644 --- a/src/Parser/psyntax.go +++ b/src/Parser/psyntax.go @@ -327,18 +327,31 @@ func (s PStatement) TypedConst() Lib.Option[Lib.Pair[string, PType]] { return s. /* A function to get a FormulaRole from a String + - "axiom"s are accepted, without proof. There is no guarantee that the axioms of a problem are consistent. + - "hypothesis"s are assumed to be true for a particular problem, and are used like "axiom"s. + - "definition"s are intended to define symbols. They are either universally quantified equations, or universally quantified equivalences with an atomic lefthand side. They can be treated like "axiom"s. + - "assumption"s can be used like axioms, but must be discharged before a derivation is complete. + - "lemma"s and "theorem"s have been proven from the "axiom"s. They can be used like "axiom"s in problems, and a problem containing a non-redundant + - "lemma" or theorem" is ill-formed. They can also appear in derivations. + - "theorem"s are more important than "lemma"s from the user perspective. + - "conjecture"s are to be proven from the "axiom"(-like) formulae. A problem is solved only when all "conjecture"s are proven. + - "negated_conjecture"s are formed from negation of a "conjecture" (usually in a FOF to CNF conversion). + - "plain"s have no specified user semantics. + - "fi_domain", "fi_functors", and "fi_predicates" are used to record the domain, interpretation of functors, and interpretation of predicates, for a finite interpretation. + - "type" defines the type globally for one symbol; treat as $true. + - "unknown"s have unknown role, and this is an error situation. */ func PFormulaRoleFromStr(role string) PFormulaRole { diff --git a/src/Parser/tptp_lex.go b/src/Parser/tptp_lex.go index 8ed66305..1695620a 100644 --- a/src/Parser/tptp_lex.go +++ b/src/Parser/tptp_lex.go @@ -398,13 +398,15 @@ func (lexer *TPTPLex) distinctObject(yylval *TPTPSymType) { // ::: ([\40-\46\50-\133\135-\176]|[\\]['\\]) func (lexer TPTPLex) isSqChar() bool { ascii := int(lexer.c) - return (ascii >= 32 && ascii <= 38) || (ascii >= 40 && ascii <= 91) || (ascii >= 93 && ascii <= 126) + return (ascii >= 32 && ascii <= 38) || (ascii >= 40 && ascii <= 91) || + (ascii >= 93 && ascii <= 126) } // ::: ([\40-\41\43-\133\135-\176]|[\\]["\\]) func (lexer TPTPLex) isDoChar() bool { ascii := int(lexer.c) - return (ascii >= 32 && ascii <= 33) || (ascii >= 35 && ascii <= 91) || (ascii >= 93 && ascii <= 126) + return (ascii >= 32 && ascii <= 33) || (ascii >= 35 && ascii <= 91) || + (ascii >= 93 && ascii <= 126) } // ---------------------------------------------------------------------------- diff --git a/src/Search/child_management.go b/src/Search/child_management.go index a02c580c..b1e6cfcc 100644 --- a/src/Search/child_management.go +++ b/src/Search/child_management.go @@ -74,7 +74,21 @@ func MakeWcdArgs( childOrdering []int, toReintroduce []int, ) wcdArgs { - return wcdArgs{fatherId, st, c, children, givenSubsts, currentSubst, substsBT, formsBT, nodeId, originalNodeId, overwrite, childOrdering, toReintroduce} + return wcdArgs{ + fatherId, + st, + c, + children, + givenSubsts, + currentSubst, + substsBT, + formsBT, + nodeId, + originalNodeId, + overwrite, + childOrdering, + toReintroduce, + } } func (args wcdArgs) printDebugMessages() { @@ -100,7 +114,8 @@ func (args wcdArgs) printDebugMessages() { args.st.GetBTOnFormulas(), Core.SubstAndFormListToString(args.givenSubsts), args.st.GetAppliedSubst().ToString(), - Core.SubstAndFormListToString(args.st.GetSubstsFound())) + Core.SubstAndFormListToString(args.st.GetSubstsFound()), + ) }), ) debug(Lib.MkLazy(func() string { @@ -119,16 +134,26 @@ func (args wcdArgs) printDebugMessages() { /* Utilitary subfunctions */ -func (ds *destructiveSearch) childrenClosedByThemselves(args wcdArgs, proofChildren [][]ProofStruct) error { +func (ds *destructiveSearch) childrenClosedByThemselves( + args wcdArgs, + proofChildren [][]ProofStruct, +) error { debug(Lib.MkLazy(func() string { return "All children has finished by themselves" })) // All children are closed & did not send any subst, i.e., they can be closed. closeChildren(&args.children, true) // Remove all the metavariables that have been introduced in this node: the parent do not know them. - substForFather := Core.RemoveElementWithoutMM(args.st.GetAppliedSubst().GetSubst(), args.st.GetMM()) + substForFather := Core.RemoveElementWithoutMM( + args.st.GetAppliedSubst().GetSubst(), + args.st.GetMM(), + ) if !substForFather.IsEmpty() { - args.st.SetSubstsFound([]Core.SubstAndForm{Core.MakeSubstAndForm(substForFather, args.st.GetAppliedSubst().GetForm())}) + args.st.SetSubstsFound( + []Core.SubstAndForm{ + Core.MakeSubstAndForm(substForFather, args.st.GetAppliedSubst().GetForm()), + }, + ) } else { args.st.SetSubstsFound([]Core.SubstAndForm{}) } @@ -136,26 +161,51 @@ func (ds *destructiveSearch) childrenClosedByThemselves(args wcdArgs, proofChild // No need to append the current substitution, because the children returns it anyway (if it exists) // So here, the current substitution should be empty. Otherwise, there's a big bug somewhere else. if !args.currentSubst.IsEmpty() { - return errors.New("current substitution is not empty but children close by themselves which shouldn't happen") + return errors.New( + "current substitution is not empty but children close by themselves which shouldn't happen", + ) } // Updates the proof using the proofs of the children of the node. args.st = updateProof(args, proofChildren) toMerge := Core.MakeUnifier() - toMerge.AddSubstitutions(args.st.GetAppliedSubst().GetSubst(), args.st.GetAppliedSubst().GetSubst()) + toMerge.AddSubstitutions( + args.st.GetAppliedSubst().GetSubst(), + args.st.GetAppliedSubst().GetSubst(), + ) unifier := args.st.GetGlobUnifier() unifier.Merge(toMerge) unifier.PruneMetasInSubsts(args.st.GetMC()) args.st.SetGlobUnifier(unifier) - WriteExchanges(args.fatherId, args.st, nil, Core.MakeEmptySubstAndForm(), "WaitChildren - To father - all closed") + WriteExchanges( + args.fatherId, + args.st, + nil, + Core.MakeEmptySubstAndForm(), + "WaitChildren - To father - all closed", + ) - ds.sendSubToFather(args.c, true, false, args.fatherId, args.st, args.givenSubsts, args.nodeId, args.originalNodeId, args.toReintroduce) + ds.sendSubToFather( + args.c, + true, + false, + args.fatherId, + args.st, + args.givenSubsts, + args.nodeId, + args.originalNodeId, + args.toReintroduce, + ) return nil } -func (ds *destructiveSearch) passSubstToParent(args wcdArgs, proofChildren [][]ProofStruct, substs []Core.SubstAndForm) error { +func (ds *destructiveSearch) passSubstToParent( + args wcdArgs, + proofChildren [][]ProofStruct, + substs []Core.SubstAndForm, +) error { debug( Lib.MkLazy(func() string { return fmt.Sprintf( @@ -190,7 +240,10 @@ func (ds *destructiveSearch) passSubstToParent(args wcdArgs, proofChildren [][]P err, merged := Core.MergeSubstAndForm(subst, args.st.GetAppliedSubst()) if err != nil { - Glob.PrintError("WC", "Error when merging the children substitution's with the applied one.") + Glob.PrintError( + "WC", + "Error when merging the children substitution's with the applied one.", + ) return err } @@ -207,12 +260,17 @@ func (ds *destructiveSearch) passSubstToParent(args wcdArgs, proofChildren [][]P for i := 0; !added && i < len(resultingSubsts); i++ { if resultingSubstsAndForms[i].GetSubst().Equals(cleaned) { added = true - resultingSubstsAndForms[i] = resultingSubstsAndForms[i].AddFormulas(subst.GetForm()) + resultingSubstsAndForms[i] = resultingSubstsAndForms[i].AddFormulas( + subst.GetForm(), + ) } } if !added { - resultingSubstsAndForms = append(resultingSubstsAndForms, substAndFormCleaned.Copy()) + resultingSubstsAndForms = append( + resultingSubstsAndForms, + substAndFormCleaned.Copy(), + ) resultingSubsts = append(resultingSubsts, substAndFormCleaned.GetSubst()) } @@ -231,7 +289,10 @@ func (ds *destructiveSearch) passSubstToParent(args wcdArgs, proofChildren [][]P } toMerge := Core.MakeUnifier() - toMerge.AddSubstitutions(args.st.GetAppliedSubst().GetSubst(), args.st.GetAppliedSubst().GetSubst()) + toMerge.AddSubstitutions( + args.st.GetAppliedSubst().GetSubst(), + args.st.GetAppliedSubst().GetSubst(), + ) unifier := args.st.GetGlobUnifier() unifier.Merge(toMerge) unifier.PruneMetasInSubsts(args.st.GetMC()) @@ -239,16 +300,35 @@ func (ds *destructiveSearch) passSubstToParent(args wcdArgs, proofChildren [][]P resultingSubstsAndForms = Core.RemoveEmptySubstFromSubstAndFormList(resultingSubstsAndForms) args.st.SetSubstsFound(resultingSubstsAndForms) - WriteExchanges(args.fatherId, args.st, resultingSubstsAndForms, Core.MakeEmptySubstAndForm(), "WaitChildren - To father - all agree") + WriteExchanges( + args.fatherId, + args.st, + resultingSubstsAndForms, + Core.MakeEmptySubstAndForm(), + "WaitChildren - To father - all agree", + ) closeChildren(&args.children, true) - ds.sendSubToFather(args.c, true, len(args.st.GetSubstsFound()) != 0, args.fatherId, args.st, args.givenSubsts, args.nodeId, args.originalNodeId, newMetas) + ds.sendSubToFather( + args.c, + true, + len(args.st.GetSubstsFound()) != 0, + args.fatherId, + args.st, + args.givenSubsts, + args.nodeId, + args.originalNodeId, + newMetas, + ) return nil } // If there is a problem of a child always checking the same substitution, it can be avoided here. func (bs *destructiveSearch) passSubstToChildren(args wcdArgs, substs []Core.SubstAndForm) { - subst, resultingSubsts := bs.chooseSubstitutionDestructive(Core.CopySubstAndFormList(substs), args.st.GetMM()) + subst, resultingSubsts := bs.chooseSubstitutionDestructive( + Core.CopySubstAndFormList(substs), + args.st.GetMM(), + ) debug( Lib.MkLazy(func() string { return fmt.Sprintf( @@ -278,7 +358,12 @@ func (ds *destructiveSearch) manageOpenedChild(args wcdArgs) { // If the completeness mode is active, then we need to deal with forbidden substitutions. if Glob.GetCompleteness() { - args.st.SetForbiddenSubsts(Unif.AddSubstToSubstitutionsList(args.st.GetForbiddenSubsts(), args.currentSubst.GetSubst())) + args.st.SetForbiddenSubsts( + Unif.AddSubstToSubstitutionsList( + args.st.GetForbiddenSubsts(), + args.currentSubst.GetSubst(), + ), + ) } if args.st.GetBTOnFormulas() && len(args.formsBT) > 0 { @@ -322,12 +407,22 @@ func (ds *destructiveSearch) manageBacktrackForDMT(args wcdArgs) { nextSaF := args.formsBT[0].Copy() nextForm := nextSaF.GetSaf().GetForm()[0].Copy() args.formsBT = args.formsBT[1:] - WriteExchanges(args.fatherId, args.st, []Core.SubstAndForm{}, nextSaF.GetSaf().ToSubstAndForm(), "WaitChildren - Backtrack on form") + WriteExchanges( + args.fatherId, + args.st, + []Core.SubstAndForm{}, + nextSaF.GetSaf().ToSubstAndForm(), + "WaitChildren - Backtrack on form", + ) childNode := Glob.IncrCptNode() // Update the proof-tree with the - args.st.SetCurrentProofResultFormulas([]IntFormAndTermsList{MakeIntFormAndTermsList(childNode, Core.MakeSingleElementFormAndTermList(nextForm))}) + args.st.SetCurrentProofResultFormulas( + []IntFormAndTermsList{ + MakeIntFormAndTermsList(childNode, Core.MakeSingleElementFormAndTermList(nextForm)), + }, + ) args.st.SetCurrentProofRule("Rewrite") args.st.SetCurrentProofRuleName("Rewrite") args.st.SetCurrentProofIdDMT(nextSaF.GetId_rewrite()) @@ -337,7 +432,16 @@ func (ds *destructiveSearch) manageBacktrackForDMT(args wcdArgs) { copiedState := args.st.Copy() communicationChild := Communication{make(chan bool), make(chan Result)} - go ds.ProofSearch(Glob.GetGID(), copiedState, communicationChild, nextSaF.GetSaf().ToSubstAndForm(), childNode, args.originalNodeId, args.toReintroduce, false) + go ds.ProofSearch( + Glob.GetGID(), + copiedState, + communicationChild, + nextSaF.GetSaf().ToSubstAndForm(), + childNode, + args.originalNodeId, + args.toReintroduce, + false, + ) debug(Lib.MkLazy(func() string { return "GO !" })) Glob.IncrGoRoutine(1) @@ -355,7 +459,8 @@ func updateProof(args wcdArgs, proofChildren [][]ProofStruct) State { proofList := args.st.GetProof() if args.overwrite { // TODO: check if it gets properly rewritten when a backtrack on it is done. - if proofList[len(proofList)-1].Rule == "Rewrite" && (proofChildren[0][0].Rule != "Rewrite" || proofChildren[0][0].Node_id != proofList[len(proofList)-1].Node_id) { + if proofList[len(proofList)-1].Rule == "Rewrite" && + (proofChildren[0][0].Rule != "Rewrite" || proofChildren[0][0].Node_id != proofList[len(proofList)-1].Node_id) { proofList[len(proofList)-1].Children = [][]ProofStruct{} proofList = append(proofList, proofChildren[0]...) } else { diff --git a/src/Search/children.go b/src/Search/children.go index 4e94c0b7..a25ae713 100644 --- a/src/Search/children.go +++ b/src/Search/children.go @@ -102,7 +102,18 @@ func (r Result) getUnifier() Core.Unifier { } func (r Result) Copy() Result { - return Result{r.getId(), r.isClosed(), r.needsAnswer(), r.getSubstForChildren(), r.getSubstListForFather(), r.getForbiddenSubsts(), r.getProof(), r.getNodeId(), r.getOriginalNodeId(), r.getUnifier()} + return Result{ + r.getId(), + r.isClosed(), + r.needsAnswer(), + r.getSubstForChildren(), + r.getSubstListForFather(), + r.getForbiddenSubsts(), + r.getProof(), + r.getNodeId(), + r.getOriginalNodeId(), + r.getUnifier(), + } } /* remove a childre from a communication list */ @@ -123,7 +134,9 @@ func removeChildren(s []Communication, removals Lib.Set[Lib.Int]) []Communicatio **/ func closeChildren(children *[]Communication, kill bool) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Close children : %v, order : %v", len(*children), kill) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Close children : %v, order : %v", len(*children), kill) }, + ), ) delayed_removal := Lib.EmptySet[Lib.Int]() @@ -158,11 +171,15 @@ func closeChildren(children *[]Communication, kill bool) { /* Send a substitution to a list of child */ func sendSubToChildren(children []Communication, s Core.SubstAndForm) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Send sub to children : %v", len(children)) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Send sub to children : %v", len(children)) }, + ), ) for i, v := range children { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("children : %v/%v", i+1, len(children)) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("children : %v/%v", i+1, len(children)) }, + ), ) v.result <- Result{Glob.GetGID(), true, true, s.Copy(), []Core.SubstAndForm{}, Unif.MakeEmptySubstitutionList(), nil, -1, -1, Core.MakeUnifier()} } @@ -171,18 +188,31 @@ func sendSubToChildren(children []Communication, s Core.SubstAndForm) { /* Send a substitution to a list of child */ func sendForbiddenToChildren(children []Communication, s []Unif.Substitutions) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Send forbidden to children : %v", len(children)) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Send forbidden to children : %v", len(children)) }, + ), ) for i, v := range children { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("children : %v/%v", i+1, len(children)) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("children : %v/%v", i+1, len(children)) }, + ), ) v.result <- Result{Glob.GetGID(), true, true, Core.MakeEmptySubstAndForm(), []Core.SubstAndForm{}, s, nil, -1, -1, Core.MakeUnifier()} } } /* Send a subst to father. Return true if the process is supposed to die after */ -func (ds *destructiveSearch) sendSubToFather(c Communication, closed, need_answer bool, father_id uint64, st State, given_substs []Core.SubstAndForm, node_id int, original_node_id int, meta_to_reintroduce []int) { +func (ds *destructiveSearch) sendSubToFather( + c Communication, + closed, need_answer bool, + father_id uint64, + st State, + given_substs []Core.SubstAndForm, + node_id int, + original_node_id int, + meta_to_reintroduce []int, +) { subst_for_father := Core.RemoveEmptySubstFromSubstAndFormList(st.GetSubstsFound()) debug( Lib.MkLazy(func() string { @@ -208,7 +238,9 @@ func (ds *destructiveSearch) sendSubToFather(c Communication, closed, need_answe }), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Send proof : %v", ProofStructListToString(st.GetProof())) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Send proof : %v", ProofStructListToString(st.GetProof())) }, + ), ) debug( Lib.MkLazy(func() string { @@ -221,11 +253,31 @@ func (ds *destructiveSearch) sendSubToFather(c Communication, closed, need_answe select { case c.result <- Result{Glob.GetGID(), closed, need_answer, Core.MakeEmptySubstAndForm(), Core.CopySubstAndFormList(subst_for_father), Unif.MakeEmptySubstitutionList(), st.GetProof(), node_id, original_node_id, st.GetGlobUnifier()}: if need_answer { - ds.waitFather(father_id, st, c, Core.FusionSubstAndFormListWithoutDouble(subst_for_father, given_substs), node_id, original_node_id, []int{}, meta_to_reintroduce) + ds.waitFather( + father_id, + st, + c, + Core.FusionSubstAndFormListWithoutDouble(subst_for_father, given_substs), + node_id, + original_node_id, + []int{}, + meta_to_reintroduce, + ) } else { debug(Lib.MkLazy(func() string { return "Die" })) } case quit := <-c.quit: - ds.manageQuitOrder(quit, c, father_id, st, []Communication{}, given_substs, node_id, original_node_id, []int{}, meta_to_reintroduce) + ds.manageQuitOrder( + quit, + c, + father_id, + st, + []Communication{}, + given_substs, + node_id, + original_node_id, + []int{}, + meta_to_reintroduce, + ) } } diff --git a/src/Search/destructive.go b/src/Search/destructive.go index ba555609..b0fb21ce 100644 --- a/src/Search/destructive.go +++ b/src/Search/destructive.go @@ -62,7 +62,15 @@ type BasicSearchAlgorithm interface { ProofSearch(uint64, State, Communication, Core.SubstAndForm, int, int, []int, bool) DoEndManageBeta(uint64, State, Communication, []Communication, int, int, []int, []int) manageRewriteRules(uint64, State, Communication, Core.FormAndTermsList, int, int, []int) - ManageClosureRule(uint64, *State, Communication, []Unif.Substitutions, Core.FormAndTerms, int, int) (bool, []Core.SubstAndForm) + ManageClosureRule( + uint64, + *State, + Communication, + []Unif.Substitutions, + Core.FormAndTerms, + int, + int, + ) (bool, []Core.SubstAndForm) manageResult(c Communication) (Core.Unifier, []ProofStruct, bool) } @@ -76,7 +84,9 @@ func NewDestructiveSearch() BasicSearchAlgorithm { return ds } -func (ds *destructiveSearch) SetApplyRules(function func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int)) { +func (ds *destructiveSearch) SetApplyRules( + function func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int), +) { ds.doCorrectApplyRules = function } func (ds *destructiveSearch) Search(formula AST.Form, bound int) bool { @@ -119,20 +129,39 @@ func (ds *destructiveSearch) doOneStep(limit int, formula AST.Form) (bool, int) c := MakeCommunication(make(chan bool), make(chan Result)) if Glob.GetExchanges() { - WriteExchanges(Glob.GetGID(), state, []Core.SubstAndForm{}, Core.MakeEmptySubstAndForm(), "Search") + WriteExchanges( + Glob.GetGID(), + state, + []Core.SubstAndForm{}, + Core.MakeEmptySubstAndForm(), + "Search", + ) } nodeId := Glob.IncrCptNode() - go ds.ProofSearch(Glob.GetGID(), state, c, Core.MakeEmptySubstAndForm(), nodeId, nodeId, []int{}, false) + go ds.ProofSearch( + Glob.GetGID(), + state, + c, + Core.MakeEmptySubstAndForm(), + nodeId, + nodeId, + []int{}, + false, + ) Glob.IncrGoRoutine(1) debug(Lib.MkLazy(func() string { return "GO" })) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Nb of goroutines = %d", Glob.GetNbGoroutines()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Nb of goroutines = %d", Glob.GetNbGoroutines()) }, + ), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("%v goroutines still running", runtime.NumGoroutine()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("%v goroutines still running", runtime.NumGoroutine()) }, + ), ) unifier, finalProof, result := ds.manageResult(c) @@ -154,7 +183,11 @@ func (ds *destructiveSearch) doOneStep(limit int, formula AST.Form) (bool, int) } /* Choose a substitution (backtrack) */ -func (ds *destructiveSearch) tryBTSubstitution(spc *([]Core.SubstAndForm), mm Lib.Set[AST.Meta], children []Communication) Core.SubstAndForm { +func (ds *destructiveSearch) tryBTSubstitution( + spc *([]Core.SubstAndForm), + mm Lib.Set[AST.Meta], + children []Communication, +) Core.SubstAndForm { debug(Lib.MkLazy(func() string { return "Try another substitution." })) next_subst, new_spc := ds.chooseSubstitutionDestructive(Core.CopySubstAndFormList(*spc), mm) debug( @@ -170,7 +203,10 @@ func (ds *destructiveSearch) tryBTSubstitution(spc *([]Core.SubstAndForm), mm Li } /* Choose a substitution among all the subst send by children - takes thoses who contains no mm first */ -func (ds *destructiveSearch) chooseSubstitutionDestructive(subst_list []Core.SubstAndForm, mm Lib.Set[AST.Meta]) (Core.SubstAndForm, []Core.SubstAndForm) { +func (ds *destructiveSearch) chooseSubstitutionDestructive( + subst_list []Core.SubstAndForm, + mm Lib.Set[AST.Meta], +) (Core.SubstAndForm, []Core.SubstAndForm) { subst_found := subst_list[0] found := false i := 0 @@ -204,36 +240,69 @@ func (ds *destructiveSearch) chooseSubstitutionDestructive(subst_list []Core.Sub return subst_found, subst_list } -func (ds *destructiveSearch) searchContradictionAfterApplySusbt(father_id uint64, st State, cha Communication, node_id int, original_node_id int) bool { +func (ds *destructiveSearch) searchContradictionAfterApplySusbt( + father_id uint64, + st State, + cha Communication, + node_id int, + original_node_id int, +) bool { if Glob.GetAssisted() { return false } for _, f := range st.GetAtomic() { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("##### Formula %v #####", f.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("##### Formula %v #####", f.ToString()) }, + ), ) // Check if exists a contradiction after applying the substitution if res, subst := ApplyClosureRules(f.GetForm(), &st); res { - ds.ManageClosureRule(father_id, &st, cha, Unif.CopySubstList(subst), f.Copy(), node_id, original_node_id) + ds.ManageClosureRule( + father_id, + &st, + cha, + Unif.CopySubstList(subst), + f.Copy(), + node_id, + original_node_id, + ) return true } } return false } -func (ds *destructiveSearch) searchContradiction(atomic AST.Form, father_id uint64, st State, cha Communication, node_id int, original_node_id int) bool { +func (ds *destructiveSearch) searchContradiction( + atomic AST.Form, + father_id uint64, + st State, + cha Communication, + node_id int, + original_node_id int, +) bool { // Search for a contradiction in LF if Glob.GetAssisted() { return false } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("##### Formula %v #####", atomic.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("##### Formula %v #####", atomic.ToString()) }, + ), ) clos_res, subst := ApplyClosureRules(atomic, &st) fAt := Core.MakeFormAndTerm(atomic, Lib.MkList[AST.Term](0)) if clos_res { - ds.ManageClosureRule(father_id, &st, cha, Unif.CopySubstList(subst), fAt, node_id, original_node_id) + ds.ManageClosureRule( + father_id, + &st, + cha, + Unif.CopySubstList(subst), + fAt, + node_id, + original_node_id, + ) return true } return false @@ -248,7 +317,16 @@ func (ds *destructiveSearch) searchContradiction(atomic AST.Form, father_id uint * s : substitution to apply to the current State * subst_found : Unif.Substitutions found by this process **/ -func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communication, s Core.SubstAndForm, node_id int, original_node_id int, meta_to_reintroduce []int, post_dmt_step bool) { +func (ds *destructiveSearch) ProofSearch( + father_id uint64, + st State, + cha Communication, + s Core.SubstAndForm, + node_id int, + original_node_id int, + meta_to_reintroduce []int, + post_dmt_step bool, +) { debug( Lib.MkLazy(func() string { return "---------- New search step ----------" }), ) @@ -276,18 +354,37 @@ func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communi // Select to check kill order select { case quit := <-cha.quit: - ds.manageQuitOrder(quit, cha, father_id, st, nil, st.GetSubstsFound(), node_id, original_node_id, nil, meta_to_reintroduce) + ds.manageQuitOrder( + quit, + cha, + father_id, + st, + nil, + st.GetSubstsFound(), + node_id, + original_node_id, + nil, + meta_to_reintroduce, + ) default: // Apply subst if needed if !s.IsEmpty() { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Apply Substitution : %v", s.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Apply Substitution : %v", s.ToString()) }, + ), ) ApplySubstitution(&st, s) debug( Lib.MkLazy(func() string { return "Searching contradiction with new atomics" }), ) - if ds.searchContradictionAfterApplySusbt(father_id, st, cha, node_id, original_node_id) { + if ds.searchContradictionAfterApplySusbt( + father_id, + st, + cha, + node_id, + original_node_id, + ) { return } } @@ -299,12 +396,17 @@ func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communi Lib.MkLazy(func() string { return fmt.Sprintf( "Current substitutions list: %v", - Unif.SubstListToString(Core.GetSubstListFromSubstAndFormList(st.GetSubstsFound()))) + Unif.SubstListToString( + Core.GetSubstListFromSubstAndFormList(st.GetSubstsFound()), + ), + ) }), ) } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Formulas to be added: %v", st.GetLF().ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Formulas to be added: %v", st.GetLF().ToString()) }, + ), ) // Dispatch newly generated formulas into the right category @@ -313,7 +415,15 @@ func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communi for _, f := range st.GetLF() { if Core.ShowKindOfRule(f.GetForm()) == Core.Atomic { if searchObviousClosureRule(f.GetForm()) { - ds.ManageClosureRule(father_id, &st, cha, []Unif.Substitutions{}, f, node_id, original_node_id) + ds.ManageClosureRule( + father_id, + &st, + cha, + []Unif.Substitutions{}, + f, + node_id, + original_node_id, + ) return } step_atomics = append(step_atomics, f) @@ -324,19 +434,34 @@ func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communi // DMT --- Retrieve atomics for DMT debug( - Lib.MkLazy(func() string { return fmt.Sprintf("New atomics : %v", step_atomics.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("New atomics : %v", step_atomics.ToString()) }, + ), ) atomics_dmt, atomics_non_dmt := ds.getAtomicsForDMT(step_atomics, &st, s, post_dmt_step) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Atomics dmt : %v", atomics_dmt.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Atomics dmt : %v", atomics_dmt.ToString()) }, + ), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Atomics non-dmt : %v", atomics_non_dmt.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Atomics non-dmt : %v", atomics_non_dmt.ToString()) }, + ), ) // Equality - if EagerEq || (len(st.GetAlpha()) == 0 && len(st.GetDelta()) == 0 && len(st.GetBeta()) == 0) { - if TryEquality(atomics_dmt, st, step_atomics, father_id, cha, node_id, original_node_id) { + if EagerEq || + (len(st.GetAlpha()) == 0 && len(st.GetDelta()) == 0 && len(st.GetBeta()) == 0) { + if TryEquality( + atomics_dmt, + st, + step_atomics, + father_id, + cha, + node_id, + original_node_id, + ) { return } } @@ -345,24 +470,47 @@ func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communi atomicsPlus := atomics_non_dmt.FilterLitPolarity(Core.Pos) atomicsMinus := atomics_non_dmt.FilterLitPolarity(Core.Neg) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Atomic plus : %v", atomicsPlus.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Atomic plus : %v", atomicsPlus.ToString()) }, + ), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Atomic minus : %v", atomicsMinus.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Atomic minus : %v", atomicsMinus.ToString()) }, + ), + ) + st.SetTreePos( + st.GetTreePos().MakeDataStruct(st.GetAtomic().Merge(atomicsPlus).ExtractForms(), true), + ) + st.SetTreeNeg( + st.GetTreeNeg(). + MakeDataStruct(st.GetAtomic().Merge(atomicsMinus).ExtractForms(), false), ) - st.SetTreePos(st.GetTreePos().MakeDataStruct(st.GetAtomic().Merge(atomicsPlus).ExtractForms(), true)) - st.SetTreeNeg(st.GetTreeNeg().MakeDataStruct(st.GetAtomic().Merge(atomicsMinus).ExtractForms(), false)) for _, f := range atomics_non_dmt { st.DispatchForm(f) } for _, f := range atomicsPlus { - if ds.searchContradiction(f.GetForm().Copy(), father_id, st, cha, node_id, original_node_id) { + if ds.searchContradiction( + f.GetForm().Copy(), + father_id, + st, + cha, + node_id, + original_node_id, + ) { return } } for _, f := range atomicsMinus { - if ds.searchContradiction(f.GetForm().Copy(), father_id, st, cha, node_id, original_node_id) { + if ds.searchContradiction( + f.GetForm().Copy(), + father_id, + st, + cha, + node_id, + original_node_id, + ) { return } } @@ -380,7 +528,15 @@ func (ds *destructiveSearch) ProofSearch(father_id uint64, st State, cha Communi ) // DoCorrectApplyRules is defined by default as ApplyRules, or to ApplyRulesAssisted if assisted flag is given. - go ds.doCorrectApplyRules(father_id, st, cha, atomics_dmt, node_id, original_node_id, meta_to_reintroduce) + go ds.doCorrectApplyRules( + father_id, + st, + cha, + atomics_dmt, + node_id, + original_node_id, + meta_to_reintroduce, + ) } } @@ -396,7 +552,12 @@ var TryEquality = func(atomics_for_dmt Core.FormAndTermsList, st State, new_atom * or the subst to apply is empty * = !(i is last and getBtOnFOrm and subst not null) **/ -func (ds *destructiveSearch) getAtomicsForDMT(new_atomics Core.FormAndTermsList, st *State, s Core.SubstAndForm, post_dmt_step bool) (Core.FormAndTermsList, Core.FormAndTermsList) { +func (ds *destructiveSearch) getAtomicsForDMT( + new_atomics Core.FormAndTermsList, + st *State, + s Core.SubstAndForm, + post_dmt_step bool, +) (Core.FormAndTermsList, Core.FormAndTermsList) { if post_dmt_step { return Core.MakeEmptyFormAndTermsList(), new_atomics } else { @@ -419,8 +580,25 @@ func (ds *destructiveSearch) waitChildren(args wcdArgs) { select { case quit := <-args.c.quit: - WriteExchanges(args.fatherId, args.st, args.givenSubsts, args.currentSubst, "WaitChildren - Die") - ds.manageQuitOrder(quit, args.c, args.fatherId, args.st, args.children, args.givenSubsts, args.nodeId, args.originalNodeId, args.childOrdering, args.toReintroduce) + WriteExchanges( + args.fatherId, + args.st, + args.givenSubsts, + args.currentSubst, + "WaitChildren - Die", + ) + ds.manageQuitOrder( + quit, + args.c, + args.fatherId, + args.st, + args.children, + args.givenSubsts, + args.nodeId, + args.originalNodeId, + args.childOrdering, + args.toReintroduce, + ) return default: debug( @@ -430,7 +608,12 @@ func (ds *destructiveSearch) waitChildren(args wcdArgs) { args.currentSubst.GetSubst().ToString()) }), ) - status, substs, proofs, unifiers := ds.selectChildren(args.c, &args.children, args.currentSubst, args.childOrdering) + status, substs, proofs, unifiers := ds.selectChildren( + args.c, + &args.children, + args.currentSubst, + args.childOrdering, + ) debug( Lib.MkLazy(func() string { return fmt.Sprintf( @@ -452,20 +635,55 @@ func (ds *destructiveSearch) waitChildren(args wcdArgs) { case SUBST_FOR_CHILDREN: ds.passSubstToChildren(args, substs) case QUIT: - WriteExchanges(args.fatherId, args.st, args.givenSubsts, args.currentSubst, "WaitChildren - Die") + WriteExchanges( + args.fatherId, + args.st, + args.givenSubsts, + args.currentSubst, + "WaitChildren - Die", + ) debug(Lib.MkLazy(func() string { return "Closing order received" })) - ds.manageQuitOrder(true, args.c, args.fatherId, args.st, args.children, []Core.SubstAndForm{}, args.nodeId, args.originalNodeId, args.childOrdering, args.toReintroduce) + ds.manageQuitOrder( + true, + args.c, + args.fatherId, + args.st, + args.children, + []Core.SubstAndForm{}, + args.nodeId, + args.originalNodeId, + args.childOrdering, + args.toReintroduce, + ) case WAIT: - WriteExchanges(args.fatherId, args.st, args.givenSubsts, args.currentSubst, "WaitChildren - Wait father") + WriteExchanges( + args.fatherId, + args.st, + args.givenSubsts, + args.currentSubst, + "WaitChildren - Wait father", + ) debug(Lib.MkLazy(func() string { return "Closing order received, let's wait father" })) closeChildren(&args.children, true) - ds.waitFather(args.fatherId, args.st, args.c, args.givenSubsts, args.nodeId, args.originalNodeId, args.childOrdering, args.toReintroduce) + ds.waitFather( + args.fatherId, + args.st, + args.c, + args.givenSubsts, + args.nodeId, + args.originalNodeId, + args.childOrdering, + args.toReintroduce, + ) case OPENED: ds.manageOpenedChild(args) } if err != nil { - Glob.PrintError("WC", "Error when waiting for children. It should be an error when merging substitutions. What to do?") + Glob.PrintError( + "WC", + "Error when waiting for children. It should be an error when merging substitutions. What to do?", + ) } } } @@ -480,7 +698,16 @@ func (ds *destructiveSearch) waitChildren(args wcdArgs) { * children : list of children * given_substs : subst send by this node to its father **/ -func (ds *destructiveSearch) waitFather(father_id uint64, st State, c Communication, given_substs []Core.SubstAndForm, node_id int, original_node_id int, child_order []int, meta_to_reintroduce []int) { +func (ds *destructiveSearch) waitFather( + father_id uint64, + st State, + c Communication, + given_substs []Core.SubstAndForm, + node_id int, + original_node_id int, + child_order []int, + meta_to_reintroduce []int, +) { debug(Lib.MkLazy(func() string { return "Wait father" })) // CLear subst found @@ -488,8 +715,25 @@ func (ds *destructiveSearch) waitFather(father_id uint64, st State, c Communicat select { case quit := <-c.quit: - WriteExchanges(father_id, st, given_substs, Core.MakeEmptySubstAndForm(), "WaitFather - Die") - ds.manageQuitOrder(quit, c, father_id, st, []Communication{}, given_substs, node_id, original_node_id, child_order, meta_to_reintroduce) + WriteExchanges( + father_id, + st, + given_substs, + Core.MakeEmptySubstAndForm(), + "WaitFather - Die", + ) + ds.manageQuitOrder( + quit, + c, + father_id, + st, + []Communication{}, + given_substs, + node_id, + original_node_id, + child_order, + meta_to_reintroduce, + ) return case answer_father := <-c.result: @@ -498,11 +742,16 @@ func (ds *destructiveSearch) waitFather(father_id uint64, st State, c Communicat // Update to prune everything that shouldn't happen. WriteExchanges(father_id, st, given_substs, subst, "WaitFather") debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Substition received : %v", subst.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Substition received : %v", subst.ToString()) }, + ), ) // Check if the subst was already seen, returns eventually the subst with new formula(s) - if Unif.ContainsSubst(Core.GetSubstListFromSubstAndFormList(given_substs), answer_father.subst_for_children.GetSubst()) { + if Unif.ContainsSubst( + Core.GetSubstListFromSubstAndFormList(given_substs), + answer_father.subst_for_children.GetSubst(), + ) { debug( Lib.MkLazy(func() string { return "This substitution was sent by this child" }), ) @@ -514,11 +763,24 @@ func (ds *destructiveSearch) waitFather(father_id uint64, st State, c Communicat unifier := st.GetGlobUnifier() unifier.PruneUncompatibleSubstitutions(subst.GetSubst()) if unifier.IsEmpty() { - unifier.AddSubstitutions(st.GetAppliedSubst().GetSubst(), st.GetAppliedSubst().GetSubst()) + unifier.AddSubstitutions( + st.GetAppliedSubst().GetSubst(), + st.GetAppliedSubst().GetSubst(), + ) } st.SetGlobUnifier(unifier) st.SetSubstsFound([]Core.SubstAndForm{subst}) - ds.sendSubToFather(c, true, true, father_id, st, given_substs, node_id, original_node_id, meta_to_reintroduce) + ds.sendSubToFather( + c, + true, + true, + father_id, + st, + given_substs, + node_id, + original_node_id, + meta_to_reintroduce, + ) } else { // A substitution is chosen. As free variables are kept inside the terms, we need to apply the substitution on the code tree @@ -618,7 +880,18 @@ func (ds *destructiveSearch) waitFather(father_id uint64, st State, c Communicat } /* Manage quit or wait father order. Return true if the process is supposed to die at the end */ -func (ds *destructiveSearch) manageQuitOrder(quit bool, c Communication, father_id uint64, st State, children []Communication, given_substs []Core.SubstAndForm, node_id int, original_node_id int, child_order []int, meta_to_reintroduce []int) { +func (ds *destructiveSearch) manageQuitOrder( + quit bool, + c Communication, + father_id uint64, + st State, + children []Communication, + given_substs []Core.SubstAndForm, + node_id int, + original_node_id int, + child_order []int, + meta_to_reintroduce []int, +) { if len(children) > 0 { closeChildren(&children, true) } @@ -653,7 +926,12 @@ Result : []Core.SubstAndForm : substitutions list */ -func (ds *destructiveSearch) selectChildren(father Communication, children *[]Communication, current_subst Core.SubstAndForm, child_order []int) (int, []Core.SubstAndForm, [][]ProofStruct, []Core.Unifier) { +func (ds *destructiveSearch) selectChildren( + father Communication, + children *[]Communication, + current_subst Core.SubstAndForm, + child_order []int, +) (int, []Core.SubstAndForm, [][]ProofStruct, []Core.Unifier) { proof_tab := make([][]ProofStruct, len(child_order)) @@ -665,7 +943,10 @@ func (ds *destructiveSearch) selectChildren(father Communication, children *[]Co // Manage quit order index_quit := len(*children) - cases[index_quit] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(father.quit)} + cases[index_quit] = reflect.SelectCase{ + Dir: reflect.SelectRecv, + Chan: reflect.ValueOf(father.quit), + } // Result struct result_int := ERROR @@ -853,7 +1134,9 @@ func (ds *destructiveSearch) selectChildren(father Communication, children *[]Co if current_subst_seen { // A child returns current subst and the other nothing debug( - Lib.MkLazy(func() string { return "One on more children returns the current subst" }), + Lib.MkLazy( + func() string { return "One on more children returns the current subst" }, + ), ) result_int = SUBST_FOR_PARENT result_subst = append(result_subst, new_current_subst) @@ -908,11 +1191,44 @@ func (ds *destructiveSearch) selectChildren(father Communication, children *[]Co return result_int, result_subst, proof_tab, unifiers } -func (ds *destructiveSearch) DoEndManageBeta(fatherId uint64, state State, c Communication, channels []Communication, currentNodeId int, originalNodeId int, childIds []int, metaToReintroduce []int) { - ds.waitChildren(MakeWcdArgs(fatherId, state, c, channels, []Core.SubstAndForm{}, Core.MakeEmptySubstAndForm(), []Core.SubstAndForm{}, []Core.IntSubstAndFormAndTerms{}, currentNodeId, originalNodeId, false, childIds, metaToReintroduce)) +func (ds *destructiveSearch) DoEndManageBeta( + fatherId uint64, + state State, + c Communication, + channels []Communication, + currentNodeId int, + originalNodeId int, + childIds []int, + metaToReintroduce []int, +) { + ds.waitChildren( + MakeWcdArgs( + fatherId, + state, + c, + channels, + []Core.SubstAndForm{}, + Core.MakeEmptySubstAndForm(), + []Core.SubstAndForm{}, + []Core.IntSubstAndFormAndTerms{}, + currentNodeId, + originalNodeId, + false, + childIds, + metaToReintroduce, + ), + ) } -func (ds *destructiveSearch) manageRewriteRules(fatherId uint64, state State, c Communication, newAtomics Core.FormAndTermsList, currentNodeId int, originalNodeId int, metaToReintroduce []int) { +func (ds *destructiveSearch) manageRewriteRules( + fatherId uint64, + state State, + c Communication, + newAtomics Core.FormAndTermsList, + currentNodeId int, + originalNodeId int, + metaToReintroduce []int, +) { debug(Lib.MkLazy(func() string { return "Try rewrite rule" })) debug( Lib.MkLazy(func() string { @@ -932,13 +1248,25 @@ func (ds *destructiveSearch) manageRewriteRules(fatherId uint64, state State, c remainingAtomics = remainingAtomics[1:].Copy() debug(Lib.MkLazy(func() string { return fmt.Sprintf("Choose : %v", f.ToString()) })) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Remaining atomics %v", remainingAtomics.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Remaining atomics %v", remainingAtomics.ToString()) }, + ), ) // If f is in atomic, that means we couldn't rewrite it, so it's useless to check if !state.GetAtomic().Contains(f) && Glob.IsLoaded("dmt") { if rewritten, err := dmt.Rewrite(f.GetForm()); err == nil { - shouldReturn := ds.tryRewrite(rewritten, f, &state, remainingAtomics, fatherId, c, currentNodeId, originalNodeId, metaToReintroduce) + shouldReturn := ds.tryRewrite( + rewritten, + f, + &state, + remainingAtomics, + fatherId, + c, + currentNodeId, + originalNodeId, + metaToReintroduce, + ) if shouldReturn { return } @@ -949,11 +1277,30 @@ func (ds *destructiveSearch) manageRewriteRules(fatherId uint64, state State, c } //If no rewriting has been found, perform an "empty" step with unused axioms - ds.ProofSearch(fatherId, state, c, Core.MakeEmptySubstAndForm(), currentNodeId, originalNodeId, []int{}, true) + ds.ProofSearch( + fatherId, + state, + c, + Core.MakeEmptySubstAndForm(), + currentNodeId, + originalNodeId, + []int{}, + true, + ) } // FIXME: check if this function does not make the DMT version lose completeness: is the original formula that's rewritten still in the branch or not? -func (ds *destructiveSearch) tryRewrite(rewritten []Core.IntSubstAndForm, f Core.FormAndTerms, state *State, remainingAtomics Core.FormAndTermsList, fatherId uint64, c Communication, currentNodeId int, originalNodeId int, metaToReintroduce []int) bool { +func (ds *destructiveSearch) tryRewrite( + rewritten []Core.IntSubstAndForm, + f Core.FormAndTerms, + state *State, + remainingAtomics Core.FormAndTermsList, + fatherId uint64, + c Communication, + currentNodeId int, + originalNodeId int, + metaToReintroduce []int, +) bool { debug( Lib.MkLazy(func() string { return fmt.Sprintf( @@ -968,7 +1315,13 @@ func (ds *destructiveSearch) tryRewrite(rewritten []Core.IntSubstAndForm, f Core for _, isaf_f := range isaf.GetSaf().GetForm().Slice() { newFNTs = append(newFNTs, Core.MakeFormAndTerm(isaf_f, f.GetTerms())) } - newRewritten = append(newRewritten, Core.MakeIntSubstAndFormAndTerms(isaf.GetId_rewrite(), Core.MakeSubstAndFormAndTerms(isaf.GetSaf().GetSubst(), newFNTs))) + newRewritten = append( + newRewritten, + Core.MakeIntSubstAndFormAndTerms( + isaf.GetId_rewrite(), + Core.MakeSubstAndFormAndTerms(isaf.GetSaf().GetSubst(), newFNTs), + ), + ) } // Keep all the possibility of rewriting and choose the first one @@ -982,12 +1335,21 @@ func (ds *destructiveSearch) tryRewrite(rewritten []Core.IntSubstAndForm, f Core // Create a child with the current rewriting rule and make this process to wait for him, with a list of other subst to try // all atomics but not the chosen one state.SetLF(append(remainingAtomics.Copy(), choosenRewrittenForm.Copy())) - state.SetBTOnFormulas(true) // I need to know that I can bt on form and my child needs to know it to to don't loop + state.SetBTOnFormulas( + true, + ) // I need to know that I can bt on form and my child needs to know it to to don't loop // Proof state.SetCurrentProofFormula(f) childNode := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]IntFormAndTermsList{MakeIntFormAndTermsList(childNode, Core.MakeSingleElementFormAndTermList(choosenRewrittenForm.Copy()))}) + state.SetCurrentProofResultFormulas( + []IntFormAndTermsList{ + MakeIntFormAndTermsList( + childNode, + Core.MakeSingleElementFormAndTermList(choosenRewrittenForm.Copy()), + ), + }, + ) state.SetCurrentProofRule("Rewrite") state.SetCurrentProofRuleName("Rewrite") state.SetCurrentProofIdDMT(choosenRewritten.GetId_rewrite()) @@ -1000,10 +1362,35 @@ func (ds *destructiveSearch) tryRewrite(rewritten []Core.IntSubstAndForm, f Core otherState.SetBTOnFormulas(false) channelChild := Communication{make(chan bool), make(chan Result)} - go ds.ProofSearch(Glob.GetGID(), otherState, channelChild, choosenRewritten.GetSaf().ToSubstAndForm(), childNode, childNode, []int{}, false) + go ds.ProofSearch( + Glob.GetGID(), + otherState, + channelChild, + choosenRewritten.GetSaf().ToSubstAndForm(), + childNode, + childNode, + []int{}, + false, + ) debug(Lib.MkLazy(func() string { return "GO !" })) Glob.IncrGoRoutine(1) - ds.waitChildren(MakeWcdArgs(fatherId, *state, c, []Communication{channelChild}, []Core.SubstAndForm{}, choosenRewritten.GetSaf().ToSubstAndForm(), []Core.SubstAndForm{}, newRewritten, currentNodeId, originalNodeId, false, []int{childNode}, metaToReintroduce)) + ds.waitChildren( + MakeWcdArgs( + fatherId, + *state, + c, + []Communication{channelChild}, + []Core.SubstAndForm{}, + choosenRewritten.GetSaf().ToSubstAndForm(), + []Core.SubstAndForm{}, + newRewritten, + currentNodeId, + originalNodeId, + false, + []int{childNode}, + metaToReintroduce, + ), + ) return true } else { // No rewriting possible @@ -1023,12 +1410,23 @@ func (ds *destructiveSearch) tryRewrite(rewritten []Core.IntSubstAndForm, f Core * Manage this result, dispatch the subst and recreate data structures. * Return if the branch is closed without variable from its father **/ -func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Communication, substs []Unif.Substitutions, f Core.FormAndTerms, node_id int, original_node_id int) (bool, []Core.SubstAndForm) { +func (ds *destructiveSearch) ManageClosureRule( + father_id uint64, + st *State, + c Communication, + substs []Unif.Substitutions, + f Core.FormAndTerms, + node_id int, + original_node_id int, +) (bool, []Core.SubstAndForm) { mm := st.GetMM().Copy() subst := st.GetAppliedSubst().GetSubst() mm = mm.Union(Core.GetMetaFromSubst(subst)) - substs_with_mm, substs_with_mm_uncleared, substs_without_mm := Core.DispatchSubst(Unif.CopySubstList(substs), mm) + substs_with_mm, substs_with_mm_uncleared, substs_without_mm := Core.DispatchSubst( + Unif.CopySubstList(substs), + mm, + ) unifier := st.GetGlobUnifier() appliedSubst := st.GetAppliedSubst().GetSubst() @@ -1036,11 +1434,15 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co switch { case len(substs) == 0: debug( - Lib.MkLazy(func() string { return "Branch closed by ¬⊤ or ⊥ or a litteral and its opposite!" }), + Lib.MkLazy( + func() string { return "Branch closed by ¬⊤ or ⊥ or a litteral and its opposite!" }, + ), ) if Glob.GetAssisted() { - fmt.Printf("Branch can be closed by ¬⊤, ⊥ or a litteral and its opposite!\nApplying it automatically...\n") + fmt.Printf( + "Branch can be closed by ¬⊤, ⊥ or a litteral and its opposite!\nApplying it automatically...\n", + ) } st.SetSubstsFound([]Core.SubstAndForm{st.GetAppliedSubst()}) @@ -1058,7 +1460,17 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co // No new subst needed in the Glob unifier if !Glob.GetAssisted() { - ds.sendSubToFather(c, true, false, Glob.GetGID(), *st, []Core.SubstAndForm{}, node_id, original_node_id, []int{}) + ds.sendSubToFather( + c, + true, + false, + Glob.GetGID(), + *st, + []Core.SubstAndForm{}, + node_id, + original_node_id, + []int{}, + ) } case len(substs_without_mm) > 0: @@ -1071,7 +1483,9 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co ) if Glob.GetAssisted() && !substs_without_mm[0].IsEmpty() { - fmt.Printf("The branch can be closed by using a substitution which has no impact elsewhere!\nApplying it automatically : ") + fmt.Printf( + "The branch can be closed by using a substitution which has no impact elsewhere!\nApplying it automatically : ", + ) fmt.Printf("%v !\n", Unif.SubstListToString(substs_without_mm)) } @@ -1092,7 +1506,17 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co } st.SetGlobUnifier(unifier) if !Glob.GetAssisted() { - ds.sendSubToFather(c, true, false, Glob.GetGID(), *st, []Core.SubstAndForm{}, node_id, original_node_id, []int{}) + ds.sendSubToFather( + c, + true, + false, + Glob.GetGID(), + *st, + []Core.SubstAndForm{}, + node_id, + original_node_id, + []int{}, + ) } case len(substs_with_mm) > 0: @@ -1112,14 +1536,24 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co for _, subst_for_father := range substs_with_mm { // Check if subst_for_father is failure if subst_for_father.Equals(Unif.Failure()) { - Glob.PrintError("MCR", fmt.Sprintf("Error : SubstForFather is failure between : %v and %v \n", subst_for_father.ToString(), st.GetAppliedSubst().ToString())) + Glob.PrintError( + "MCR", + fmt.Sprintf( + "Error : SubstForFather is failure between : %v and %v \n", + subst_for_father.ToString(), + st.GetAppliedSubst().ToString(), + ), + ) } debug( Lib.MkLazy(func() string { return fmt.Sprintf("Formula = : %v", f.ToString()) }), ) // Create substAndForm with the current form and the subst found - subst_and_form_for_father := Core.MakeSubstAndForm(subst_for_father, AST.NewFormList(f.GetForm())) + subst_and_form_for_father := Core.MakeSubstAndForm( + subst_for_father, + AST.NewFormList(f.GetForm()), + ) debug( Lib.MkLazy(func() string { @@ -1130,16 +1564,25 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co ) // Merge with applied subst (if any) - err, subst_and_form_for_father := Core.MergeSubstAndForm(subst_and_form_for_father.Copy(), st.GetAppliedSubst()) + err, subst_and_form_for_father := Core.MergeSubstAndForm( + subst_and_form_for_father.Copy(), + st.GetAppliedSubst(), + ) if err != nil { - Glob.PrintError("MCR", "Contradiction found between applied subst and child subst. What to do?") + Glob.PrintError( + "MCR", + "Contradiction found between applied subst and child subst. What to do?", + ) } else { st.SetSubstsFound(Core.AppendIfNotContainsSubstAndForm(st.GetSubstsFound(), subst_and_form_for_father)) } - meta_to_reintroduce = Glob.UnionIntList(meta_to_reintroduce, retrieveMetaFromSubst(subst_for_father)) + meta_to_reintroduce = Glob.UnionIntList( + meta_to_reintroduce, + retrieveMetaFromSubst(subst_for_father), + ) } if Glob.GetAssisted() { @@ -1176,7 +1619,15 @@ func (ds *destructiveSearch) ManageClosureRule(father_id uint64, st *State, c Co } /* Apply rules with priority (closure < rewrite < alpha < delta < closure with mm < beta < gamma) */ -func (ds *destructiveSearch) applyRules(fatherId uint64, state State, c Communication, atomicDMT Core.FormAndTermsList, currentNodeId int, originalNodeId int, metaToReintroduce []int) { +func (ds *destructiveSearch) applyRules( + fatherId uint64, + state State, + c Communication, + atomicDMT Core.FormAndTermsList, + currentNodeId int, + originalNodeId int, + metaToReintroduce []int, +) { debug(Lib.MkLazy(func() string { return "ApplyRule" })) debug( Lib.MkLazy(func() string { @@ -1194,7 +1645,15 @@ func (ds *destructiveSearch) applyRules(fatherId uint64, state State, c Communic state.GetTreeNeg().Print() switch { case len(atomicDMT) > 0 && Glob.IsLoaded("dmt") && len(state.GetSubstsFound()) == 0: - ds.manageRewriteRules(fatherId, state, c, atomicDMT, currentNodeId, originalNodeId, metaToReintroduce) + ds.manageRewriteRules( + fatherId, + state, + c, + atomicDMT, + currentNodeId, + originalNodeId, + metaToReintroduce, + ) case len(state.GetAlpha()) > 0: ds.manageAlphaRules(fatherId, state, c, originalNodeId) @@ -1209,18 +1668,42 @@ func (ds *destructiveSearch) applyRules(fatherId uint64, state State, c Communic ds.manageGammaRules(fatherId, state, c, originalNodeId) case len(state.GetMetaGen()) > 0 && state.CanReintroduce(): - ds.manageReintroductionRules(fatherId, state, c, originalNodeId, metaToReintroduce, atomicDMT, currentNodeId, true) + ds.manageReintroductionRules( + fatherId, + state, + c, + originalNodeId, + metaToReintroduce, + atomicDMT, + currentNodeId, + true, + ) default: WriteExchanges(fatherId, state, nil, Core.MakeEmptySubstAndForm(), "ApplyRules - SAT") state.SetCurrentProofRule("Sat") state.SetProof(append(state.GetProof(), state.GetCurrentProof())) debug(Lib.MkLazy(func() string { return "Nothing found, return sat" })) - ds.sendSubToFather(c, false, false, fatherId, state, []Core.SubstAndForm{}, currentNodeId, originalNodeId, []int{}) + ds.sendSubToFather( + c, + false, + false, + fatherId, + state, + []Core.SubstAndForm{}, + currentNodeId, + originalNodeId, + []int{}, + ) } } -func (ds *destructiveSearch) manageAlphaRules(fatherId uint64, state State, c Communication, originalNodeId int) { +func (ds *destructiveSearch) manageAlphaRules( + fatherId uint64, + state State, + c Communication, + originalNodeId int, +) { debug(Lib.MkLazy(func() string { return "Alpha rule" })) hdf := state.GetAlpha()[0] debug(Lib.MkLazy(func() string { return fmt.Sprintf("Rule applied on : %s", hdf.ToString()) })) @@ -1231,13 +1714,29 @@ func (ds *destructiveSearch) manageAlphaRules(fatherId uint64, state State, c Co // Proof state.SetCurrentProofFormula(hdf) childId := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]IntFormAndTermsList{MakeIntFormAndTermsList(childId, resultForms)}) + state.SetCurrentProofResultFormulas( + []IntFormAndTermsList{MakeIntFormAndTermsList(childId, resultForms)}, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) - ds.ProofSearch(fatherId, state, c, Core.MakeEmptySubstAndForm(), childId, originalNodeId, []int{}, false) + ds.ProofSearch( + fatherId, + state, + c, + Core.MakeEmptySubstAndForm(), + childId, + originalNodeId, + []int{}, + false, + ) } -func (ds *destructiveSearch) manageDeltaRules(fatherId uint64, state State, c Communication, originalNodeId int) { +func (ds *destructiveSearch) manageDeltaRules( + fatherId uint64, + state State, + c Communication, + originalNodeId int, +) { debug(Lib.MkLazy(func() string { return "Delta rule" })) hdf := state.GetDelta()[0] debug(Lib.MkLazy(func() string { return fmt.Sprintf("Rule applied on : %s", hdf.ToString()) })) @@ -1248,13 +1747,31 @@ func (ds *destructiveSearch) manageDeltaRules(fatherId uint64, state State, c Co // Proof state.SetCurrentProofFormula(hdf) childId := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]IntFormAndTermsList{MakeIntFormAndTermsList(childId, resultForms)}) + state.SetCurrentProofResultFormulas( + []IntFormAndTermsList{MakeIntFormAndTermsList(childId, resultForms)}, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) - ds.ProofSearch(fatherId, state, c, Core.MakeEmptySubstAndForm(), childId, originalNodeId, []int{}, false) + ds.ProofSearch( + fatherId, + state, + c, + Core.MakeEmptySubstAndForm(), + childId, + originalNodeId, + []int{}, + false, + ) } -func (ds *destructiveSearch) manageBetaRules(fatherId uint64, state State, c Communication, currentNodeId int, originalNodeId int, metaToReintroduce []int) { +func (ds *destructiveSearch) manageBetaRules( + fatherId uint64, + state State, + c Communication, + currentNodeId int, + originalNodeId int, + metaToReintroduce []int, +) { debug(Lib.MkLazy(func() string { return "Beta rule" })) hdf := state.GetBeta()[0] debug(Lib.MkLazy(func() string { return fmt.Sprintf("Rule applied on : %s", hdf.ToString()) })) @@ -1281,7 +1798,16 @@ func (ds *destructiveSearch) manageBetaRules(fatherId uint64, state State, c Com if Glob.IsDestructive() { channelChild := Communication{make(chan bool), make(chan Result)} channels = append(channels, channelChild) - go ds.ProofSearch(Glob.GetGID(), otherState, channelChild, Core.MakeEmptySubstAndForm(), fl.GetI(), fl.GetI(), []int{}, false) + go ds.ProofSearch( + Glob.GetGID(), + otherState, + channelChild, + Core.MakeEmptySubstAndForm(), + fl.GetI(), + fl.GetI(), + []int{}, + false, + ) } else { go ds.ProofSearch(Glob.GetGID(), otherState, c, Core.MakeEmptySubstAndForm(), fl.GetI(), fl.GetI(), []int{}, false) } @@ -1291,10 +1817,24 @@ func (ds *destructiveSearch) manageBetaRules(fatherId uint64, state State, c Com } - ds.DoEndManageBeta(fatherId, state, c, channels, currentNodeId, originalNodeId, childIds, metaToReintroduce) + ds.DoEndManageBeta( + fatherId, + state, + c, + channels, + currentNodeId, + originalNodeId, + childIds, + metaToReintroduce, + ) } -func (ds *destructiveSearch) manageGammaRules(fatherId uint64, state State, c Communication, originalNodeId int) { +func (ds *destructiveSearch) manageGammaRules( + fatherId uint64, + state State, + c Communication, + originalNodeId int, +) { debug(Lib.MkLazy(func() string { return "Gamma rule" })) hdf := state.GetGamma()[0] debug(Lib.MkLazy(func() string { return fmt.Sprintf("Rule applied on : %s", hdf.ToString()) })) @@ -1318,13 +1858,33 @@ func (ds *destructiveSearch) manageGammaRules(fatherId uint64, state State, c Co // Proof state.SetCurrentProofFormula(hdf) childId := Glob.IncrCptNode() - state.SetCurrentProofResultFormulas([]IntFormAndTermsList{MakeIntFormAndTermsList(childId, newFnts)}) + state.SetCurrentProofResultFormulas( + []IntFormAndTermsList{MakeIntFormAndTermsList(childId, newFnts)}, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) - ds.ProofSearch(fatherId, state, c, Core.MakeEmptySubstAndForm(), childId, originalNodeId, []int{}, false) + ds.ProofSearch( + fatherId, + state, + c, + Core.MakeEmptySubstAndForm(), + childId, + originalNodeId, + []int{}, + false, + ) } -func (ds *destructiveSearch) manageReintroductionRules(fatherId uint64, state State, c Communication, originalNodeId int, metaToReintroduce []int, newAtomics Core.FormAndTermsList, currentNodeId int, reintroduceAnyway bool) { +func (ds *destructiveSearch) manageReintroductionRules( + fatherId uint64, + state State, + c Communication, + originalNodeId int, + metaToReintroduce []int, + newAtomics Core.FormAndTermsList, + currentNodeId int, + reintroduceAnyway bool, +) { currentMTR := -1 @@ -1339,7 +1899,9 @@ func (ds *destructiveSearch) manageReintroductionRules(fatherId uint64, state St newMetaGen := state.GetMetaGen() reslf := Core.ReintroduceMeta(&newMetaGen, currentMTR, state.GetN()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Reintroduce the formula : %s", reslf.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Reintroduce the formula : %s", reslf.ToString()) }, + ), ) state.SetLF(Core.MakeSingleElementFormAndTermList(reslf)) @@ -1351,17 +1913,32 @@ func (ds *destructiveSearch) manageReintroductionRules(fatherId uint64, state St state.SetCurrentProofRule("Reintroduction") state.SetCurrentProofRuleName("Reintroduction") state.SetCurrentProofFormula(reslf) - state.SetCurrentProofResultFormulas([]IntFormAndTermsList{MakeIntFormAndTermsList(childId, Core.MakeSingleElementFormAndTermList(reslf))}) + state.SetCurrentProofResultFormulas( + []IntFormAndTermsList{ + MakeIntFormAndTermsList(childId, Core.MakeSingleElementFormAndTermList(reslf)), + }, + ) state.SetProof(append(state.GetProof(), state.GetCurrentProof())) - ds.ProofSearch(fatherId, state, c, Core.MakeEmptySubstAndForm(), childId, originalNodeId, metaToReintroduce, false) + ds.ProofSearch( + fatherId, + state, + c, + Core.MakeEmptySubstAndForm(), + childId, + originalNodeId, + metaToReintroduce, + false, + ) } func (ds *destructiveSearch) manageResult(c Communication) (Core.Unifier, []ProofStruct, bool) { result := <-c.getResult() debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Proof : %v", ProofStructListToString(result.getProof())) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Proof : %v", ProofStructListToString(result.getProof())) }, + ), ) if result.needsAnswer() { diff --git a/src/Search/exchanges.go b/src/Search/exchanges.go index 4e680f17..5895a9b2 100644 --- a/src/Search/exchanges.go +++ b/src/Search/exchanges.go @@ -83,7 +83,13 @@ func ResetExchangesFile() { } } -func makeJsonExchanges(father_uint uint64, st State, ss_subst []Unif.Substitutions, subst_received Unif.Substitutions, calling_function string) exchanges_struct { +func makeJsonExchanges( + father_uint uint64, + st State, + ss_subst []Unif.Substitutions, + subst_received Unif.Substitutions, + calling_function string, +) exchanges_struct { // ID id_process := Glob.GetGID() id := int(id_process) @@ -125,7 +131,13 @@ func makeJsonExchanges(father_uint uint64, st State, ss_subst []Unif.Substitutio return exchanges_struct{id, version, father, forms, mm, mc, ss, sr, calling_function} } -func WriteExchanges(father uint64, st State, sub_sent []Core.SubstAndForm, subst_received Core.SubstAndForm, calling_function string) { +func WriteExchanges( + father uint64, + st State, + sub_sent []Core.SubstAndForm, + subst_received Core.SubstAndForm, + calling_function string, +) { if Glob.GetExchanges() { mutex_file_exchanges.Lock() debug(Lib.MkLazy(func() string { return calling_function })) @@ -135,7 +147,13 @@ func WriteExchanges(father uint64, st State, sub_sent []Core.SubstAndForm, subst } else { file_exchanges.WriteString("[\n") } - json_content := makeJsonExchanges(father, st, Core.RemoveEmptySubstFromSubstList(Core.GetSubstListFromSubstAndFormList(sub_sent)), subst_received.GetSubst(), calling_function) + json_content := makeJsonExchanges( + father, + st, + Core.RemoveEmptySubstFromSubstList(Core.GetSubstListFromSubstAndFormList(sub_sent)), + subst_received.GetSubst(), + calling_function, + ) json_string, _ := json.MarshalIndent(json_content, "", " ") file_exchanges.Write(json_string) mutex_file_exchanges.Unlock() diff --git a/src/Search/incremental/reintroList.go b/src/Search/incremental/reintroList.go index 72098108..704aed6e 100644 --- a/src/Search/incremental/reintroList.go +++ b/src/Search/incremental/reintroList.go @@ -30,7 +30,9 @@ func (rrl *ReintroRuleList) Copy() *ReintroRuleList { return &ReintroRuleList{reintrosCopy, limitsCopy} } -func (rrl *ReintroRuleList) TryToApply(original *RulesManager) (success bool, applied Rule, resultRules []RuleList, resultManagers []RulesManager) { +func (rrl *ReintroRuleList) TryToApply( + original *RulesManager, +) (success bool, applied Rule, resultRules []RuleList, resultManagers []RulesManager) { if !rrl.IsEmpty() { index := 0 best := rrl.reintroRules[index] @@ -66,7 +68,11 @@ func (rrl *ReintroRuleList) ToString() string { str := "{" for i := range rrl.reintroAmount { - str += strconv.Itoa(rrl.reintroAmount[i]) + ": " + rrl.reintroRules[i].GetForm().ToString() + ", " + str += strconv.Itoa( + rrl.reintroAmount[i], + ) + ": " + rrl.reintroRules[i].GetForm(). + ToString() + + ", " } return str[:len(str)-2] + "}" diff --git a/src/Search/incremental/rules.go b/src/Search/incremental/rules.go index 4fffd124..e7525e57 100644 --- a/src/Search/incremental/rules.go +++ b/src/Search/incremental/rules.go @@ -389,7 +389,10 @@ func (gne *GammaNotExists) apply() []RuleList { resultRules := RuleList{} debug(Lib.MkLazy(func() string { return "Applying " + fmt.Sprint(gne.FullString) })) - instanciatedForm, metas := Core.Instantiate(Core.MakeFormAndTerm(gne.GetForm(), gne.GetTerms()), 42) + instanciatedForm, metas := Core.Instantiate( + Core.MakeFormAndTerm(gne.GetForm(), gne.GetTerms()), + 42, + ) newTerms := gne.GetTerms().Copy(AST.Term.Copy) newTerms.Add(AST.TermEquals, AST.MetaListToTermList(metas.Elements()).GetSlice()...) resultRules = append(resultRules, makeCorrectRule(instanciatedForm.GetForm(), newTerms)) @@ -430,7 +433,10 @@ func (gf *GammaForall) apply() []RuleList { resultRules := RuleList{} debug(Lib.MkLazy(func() string { return "Applying " + fmt.Sprint(gf.FullString) })) - instanciatedForm, metas := Core.Instantiate(Core.MakeFormAndTerm(gf.GetForm(), gf.GetTerms()), 42) + instanciatedForm, metas := Core.Instantiate( + Core.MakeFormAndTerm(gf.GetForm(), gf.GetTerms()), + 42, + ) newTerms := gf.GetTerms().Copy(AST.Term.Copy) newTerms.Add(AST.TermEquals, AST.MetaListToTermList(metas.Elements()).GetSlice()...) resultRules = append(resultRules, makeCorrectRule(instanciatedForm.GetForm(), newTerms)) diff --git a/src/Search/incremental/rulesManager.go b/src/Search/incremental/rulesManager.go index 330a9b6c..5253f8b2 100644 --- a/src/Search/incremental/rulesManager.go +++ b/src/Search/incremental/rulesManager.go @@ -25,13 +25,17 @@ type RulesManager struct { } func makeRulesManager() *RulesManager { - manager := &RulesManager{reintroRules: &ReintroRuleList{}, metaVariables: Lib.NewList[AST.Meta]()} + manager := &RulesManager{ + reintroRules: &ReintroRuleList{}, + metaVariables: Lib.NewList[AST.Meta](), + } return manager } func (rm *RulesManager) onlyReintroOrClosureLeft() bool { - return len(rm.alphaRules) == 0 && len(rm.betaRules) == 0 && len(rm.gammaRules) == 0 && len(rm.deltaRules) == 0 + return len(rm.alphaRules) == 0 && len(rm.betaRules) == 0 && len(rm.gammaRules) == 0 && + len(rm.deltaRules) == 0 } func (rm *RulesManager) insertForm(formula AST.Form) { @@ -226,7 +230,9 @@ func (rm *RulesManager) getAtomicsWithoutTopOrBottom() (pos, neg RuleList) { return pos, neg } -func (rm *RulesManager) tryToApply(category RuleList) (success bool, applied Rule, resultRules []RuleList, resultManagers []RulesManager) { +func (rm *RulesManager) tryToApply( + category RuleList, +) (success bool, applied Rule, resultRules []RuleList, resultManagers []RulesManager) { success, applied, resultRules = category.TryToApply() if success { diff --git a/src/Search/incremental/search.go b/src/Search/incremental/search.go index a052eec6..c122f736 100644 --- a/src/Search/incremental/search.go +++ b/src/Search/incremental/search.go @@ -37,12 +37,22 @@ func (is *incrementalSearch) handleSearchResults() bool { return resultFound } -func (is *incrementalSearch) SetApplyRules(func(uint64, Search.State, Search.Communication, Core.FormAndTermsList, int, int, []int)) { +func (is *incrementalSearch) SetApplyRules( + func(uint64, Search.State, Search.Communication, Core.FormAndTermsList, int, int, []int), +) { Glob.PrintError("NDS", "Incremental search not compatible with the assisted plugin for now.") } // ManageClosureRule implements Search.SearchAlgorithm. -func (is *incrementalSearch) ManageClosureRule(uint64, *Search.State, Search.Communication, []Unif.Substitutions, Core.FormAndTerms, int, int) (bool, []Core.SubstAndForm) { +func (is *incrementalSearch) ManageClosureRule( + uint64, + *Search.State, + Search.Communication, + []Unif.Substitutions, + Core.FormAndTerms, + int, + int, +) (bool, []Core.SubstAndForm) { Glob.PrintError("NDS", "Incremental search not compatible with the equality plugin for now.") return false, []Core.SubstAndForm{} } diff --git a/src/Search/incremental/subsManager.go b/src/Search/incremental/subsManager.go index a39168ed..facb1dfb 100644 --- a/src/Search/incremental/subsManager.go +++ b/src/Search/incremental/subsManager.go @@ -53,7 +53,11 @@ func newSubsManager(node *SearchNode, doneSubs SubList) *SimpleSubsManager { return newSubsManagerWithChild(node, 1, doneSubs) } -func newSubsManagerWithChild(node *SearchNode, childAmount int, doneSubs SubList) *SimpleSubsManager { +func newSubsManagerWithChild( + node *SearchNode, + childAmount int, + doneSubs SubList, +) *SimpleSubsManager { return &SimpleSubsManager{node, make([]SubList, childAmount), childAmount, doneSubs} } @@ -63,7 +67,8 @@ func (ssm *SimpleSubsManager) AddClosingSubsForFather(subs SubList) { } func (ssm *SimpleSubsManager) addClosingSubs(subs SubList, childIndex int) { - ssm.closingSubsForEachChild[childIndex] = ssm.closingSubsForEachChild[childIndex].AppendIfNotContains(subs...) + ssm.closingSubsForEachChild[childIndex] = ssm.closingSubsForEachChild[childIndex].AppendIfNotContains( + subs...) sendClosingSubsToFather(ssm) } @@ -130,9 +135,17 @@ type BranchingSubsManager struct { mutex sync.Mutex } -func newBranchingSubsManager(node *SearchNode, childAmount int, doneSubs SubList) *BranchingSubsManager { +func newBranchingSubsManager( + node *SearchNode, + childAmount int, + doneSubs SubList, +) *BranchingSubsManager { counter := Glob.NewEmptySyncCounter() - bsm := &BranchingSubsManager{newSubsManagerWithChild(node, childAmount, doneSubs), counter, sync.Mutex{}} + bsm := &BranchingSubsManager{ + newSubsManagerWithChild(node, childAmount, doneSubs), + counter, + sync.Mutex{}, + } counter.SetWhenFinished(bsm.sendClosingSubsToFather) @@ -149,7 +162,8 @@ func (bsm *BranchingSubsManager) addClosingSubs(subs SubList, childIndex int) { bsm.mutex.Lock() defer bsm.mutex.Unlock() - bsm.closingSubsForEachChild[childIndex] = bsm.closingSubsForEachChild[childIndex].AppendIfNotContains(subs...) + bsm.closingSubsForEachChild[childIndex] = bsm.closingSubsForEachChild[childIndex].AppendIfNotContains( + subs...) } func (bsm *BranchingSubsManager) sendClosingSubsToFather() { @@ -191,7 +205,11 @@ type IntroSubsManager struct { subsitutes Lib.List[AST.Term] } -func newIntroSubsManager(node *SearchNode, metas Lib.List[AST.Meta], doneSubs SubList) *IntroSubsManager { +func newIntroSubsManager( + node *SearchNode, + metas Lib.List[AST.Meta], + doneSubs SubList, +) *IntroSubsManager { return &IntroSubsManager{ newSubsManager(node, doneSubs), metas, diff --git a/src/Search/incremental/substitution.go b/src/Search/incremental/substitution.go index e7985ba8..2c5eab61 100644 --- a/src/Search/incremental/substitution.go +++ b/src/Search/incremental/substitution.go @@ -13,7 +13,8 @@ type TermWrapper struct { } func (tw *TermWrapper) Equals(other *TermWrapper) bool { - return (tw.term == anyTerm && other.term == anyTerm) || (tw.term != anyTerm && other.term != anyTerm && tw.term.Equals(other.term)) + return (tw.term == anyTerm && other.term == anyTerm) || + (tw.term != anyTerm && other.term != anyTerm && tw.term.Equals(other.term)) } type SingleSub struct { diff --git a/src/Search/nonDestructiveSearch.go b/src/Search/nonDestructiveSearch.go index 46c70f2b..0e8c6fd0 100644 --- a/src/Search/nonDestructiveSearch.go +++ b/src/Search/nonDestructiveSearch.go @@ -54,20 +54,45 @@ func NewNonDestructiveSearch() BasicSearchAlgorithm { return nil } -func (nds *nonDestructiveSearch) setApplyRules(function func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int)) { - Glob.PrintError("NDS", "Non-destructive search not compatible with the assisted plugin for now.") +func (nds *nonDestructiveSearch) setApplyRules( + function func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int), +) { + Glob.PrintError( + "NDS", + "Non-destructive search not compatible with the assisted plugin for now.", + ) } -func (nds *nonDestructiveSearch) doEndManageBeta(fatherId uint64, state State, c Communication, channels []Communication, currentNodeId int, originalNodeId int, childIds []int, metaToReintroduce []int) { +func (nds *nonDestructiveSearch) doEndManageBeta( + fatherId uint64, + state State, + c Communication, + channels []Communication, + currentNodeId int, + originalNodeId int, + childIds []int, + metaToReintroduce []int, +) { debug(Lib.MkLazy(func() string { return "Die" })) } -func (nds *nonDestructiveSearch) manageRewriteRules(fatherId uint64, state State, c Communication, newAtomics Core.FormAndTermsList, currentNodeId int, originalNodeId int, metaToReintroduce []int) { +func (nds *nonDestructiveSearch) manageRewriteRules( + fatherId uint64, + state State, + c Communication, + newAtomics Core.FormAndTermsList, + currentNodeId int, + originalNodeId int, + metaToReintroduce []int, +) { Glob.PrintError("NDS", "Non-destructive search not compatible with the DMT plugin for now.") } /* Choose substitution - whitout meta in lastAppliedSubst */ -func (nds *nonDestructiveSearch) chooseSubstitutionWithoutMetaLastApplyNonDestructive(sl []Core.SubstAndForm, ml Lib.List[AST.Meta]) (Core.SubstAndForm, []Core.SubstAndForm) { +func (nds *nonDestructiveSearch) chooseSubstitutionWithoutMetaLastApplyNonDestructive( + sl []Core.SubstAndForm, + ml Lib.List[AST.Meta], +) (Core.SubstAndForm, []Core.SubstAndForm) { for i, v := range sl { if !AST.IsIncludeInsideOF(v.GetSubst().GetMeta(), ml) { return v, Core.RemoveSubstFromSubstAndFormList(i, sl) @@ -77,7 +102,10 @@ func (nds *nonDestructiveSearch) chooseSubstitutionWithoutMetaLastApplyNonDestru } /* Choose substitution - whith meta in lastAppliedSubst */ -func (nds *nonDestructiveSearch) chooseSubstitutionWithtMetaLastApplyNonDestructive(sl []Core.SubstAndForm, last_applied_subst Core.SubstAndForm) (Core.SubstAndForm, []Core.SubstAndForm) { +func (nds *nonDestructiveSearch) chooseSubstitutionWithtMetaLastApplyNonDestructive( + sl []Core.SubstAndForm, + last_applied_subst Core.SubstAndForm, +) (Core.SubstAndForm, []Core.SubstAndForm) { for i, v := range sl { if !v.GetSubst().Equals(last_applied_subst.GetSubst()) { return v, Core.RemoveSubstFromSubstAndFormList(i, sl) @@ -87,8 +115,14 @@ func (nds *nonDestructiveSearch) chooseSubstitutionWithtMetaLastApplyNonDestruct } /* Choose the best substitution among subst_found_at_this_step and subst_found */ -func (nds *nonDestructiveSearch) chooseSubstitutionNonDestructive(substs_found_this_step []Core.SubstAndForm, st *State) Core.SubstAndForm { - res, sl := nds.chooseSubstitutionWithoutMetaLastApplyNonDestructive(substs_found_this_step, st.GetLastAppliedSubst().GetSubst().GetMeta()) +func (nds *nonDestructiveSearch) chooseSubstitutionNonDestructive( + substs_found_this_step []Core.SubstAndForm, + st *State, +) Core.SubstAndForm { + res, sl := nds.chooseSubstitutionWithoutMetaLastApplyNonDestructive( + substs_found_this_step, + st.GetLastAppliedSubst().GetSubst().GetMeta(), + ) if !res.IsEmpty() { // subst without meta in last applied meta found in substs_found_at_this_step st.SetSubstsFound(append(sl, st.GetSubstsFound()...)) return res @@ -137,18 +171,30 @@ func (nds *nonDestructiveSearch) catchFormulaToInstantiate(subst_found Unif.Subs return meta_to_reintroduce } -/** Instantiate a formula with a substitution +/* +* Instantiate a formula with a substitution * Got the substitution (X, a) and reintroduce ForAll x P(x) -> need to reintroduce P(a). Remplace immediatly the new generated metavariable by a. -**/ -func (nds *nonDestructiveSearch) instantiate(fatherId uint64, state *State, c Communication, index int, s Core.SubstAndForm) { +* + */ +func (nds *nonDestructiveSearch) instantiate( + fatherId uint64, + state *State, + c Communication, + index int, + s Core.SubstAndForm, +) { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Instantiate with subst : %v ", s.GetSubst().ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Instantiate with subst : %v ", s.GetSubst().ToString()) }, + ), ) newMetaGenerator := state.GetMetaGen() reslf := Core.ReintroduceMeta(&newMetaGenerator, index, state.GetN()) state.SetMetaGen(newMetaGenerator) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Instantiate the formula : %s", reslf.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Instantiate the formula : %s", reslf.ToString()) }, + ), ) // Apply gamma rule @@ -182,7 +228,8 @@ func (nds *nonDestructiveSearch) instantiate(fatherId uint64, state *State, c Co // Trouver celle de la formula de base for _, f := range s.GetForm().Slice() { for _, term_formula := range f.GetMetas().Elements().GetSlice() { - if !found && term_formula.IsMeta() && term_formula.GetName() == new_meta.GetName() { + if !found && term_formula.IsMeta() && + term_formula.GetName() == new_meta.GetName() { association_subst.Set(new_meta, term_formula) found = true } @@ -211,7 +258,10 @@ func (nds *nonDestructiveSearch) instantiate(fatherId uint64, state *State, c Co } } - new_subst, same_key := Unif.MergeSubstitutions(association_subst, state.GetAppliedSubst().GetSubst()) + new_subst, same_key := Unif.MergeSubstitutions( + association_subst, + state.GetAppliedSubst().GetSubst(), + ) if same_key { Glob.PrintInfo("PS", "Same key in S2 and S1") } @@ -273,7 +323,12 @@ func (nds *nonDestructiveSearch) instantiate(fatherId uint64, state *State, c Co * Choose the best subtitution to instantiate : avoid the same than last used, and the one which contains meta already used in last applied **/ -func (nds *nonDestructiveSearch) manageSubstFoundNonDestructive(father_id uint64, st *State, c Communication, substs_found_at_this_step []Core.SubstAndFormAndTerms) (int, Core.SubstAndForm) { +func (nds *nonDestructiveSearch) manageSubstFoundNonDestructive( + father_id uint64, + st *State, + c Communication, + substs_found_at_this_step []Core.SubstAndFormAndTerms, +) (int, Core.SubstAndForm) { form_to_instantiate := -1 choosen_subst := Core.MakeEmptySubstAndForm() new_choosen_subst := Core.MakeEmptySubstAndForm() @@ -308,7 +363,9 @@ func (nds *nonDestructiveSearch) manageSubstFoundNonDestructive(father_id uint64 ) })) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("AreRulesApplicable : %v", st.AreRulesApplicable()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("AreRulesApplicable : %v", st.AreRulesApplicable()) }, + ), ) choosen_subst = new_choosen_subst @@ -316,7 +373,9 @@ func (nds *nonDestructiveSearch) manageSubstFoundNonDestructive(father_id uint64 // Catch all the meta which can be instantiate form_to_instantiate = nds.catchFormulaToInstantiate(choosen_subst.GetSubst()) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Form_to_instantiate : %v", form_to_instantiate) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Form_to_instantiate : %v", form_to_instantiate) }, + ), ) return form_to_instantiate, choosen_subst @@ -397,9 +456,18 @@ func (ds *nonDestructiveSearch) manageResult(c Communication) (Core.Unifier, []P time.Sleep(1 * time.Millisecond) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("open is : %v from %v", open, res.getId()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("open is : %v from %v", open, res.getId()) }, + ), + ) + Glob.PrintInfo( + "MAIN", + fmt.Sprintf( + "%v goroutines still running - %v goroutines generated", + runtime.NumGoroutine(), + Glob.GetNbGoroutines(), + ), ) - Glob.PrintInfo("MAIN", fmt.Sprintf("%v goroutines still running - %v goroutines generated", runtime.NumGoroutine(), Glob.GetNbGoroutines())) } return Core.MakeUnifier(), []ProofStruct{}, !open diff --git a/src/Search/print_proof.go b/src/Search/print_proof.go index 69cf734e..66bdad82 100644 --- a/src/Search/print_proof.go +++ b/src/Search/print_proof.go @@ -41,7 +41,11 @@ import ( "github.com/GoelandProver/Goeland/Lib" ) -var BasicOutputProofStruct = &OutputProofStruct{ProofOutput: ProofStructListToText, Name: "Basic", Extension: ".proof"} +var BasicOutputProofStruct = &OutputProofStruct{ + ProofOutput: ProofStructListToText, + Name: "Basic", + Extension: ".proof", +} type OutputProofStruct struct { ProofOutput func(finalProof []ProofStruct, metaList Lib.List[AST.Meta]) string @@ -69,7 +73,10 @@ func PrintProof(final_proof []ProofStruct, metaList Lib.Set[AST.Meta]) { fmt.Printf("%v SZS output end Proof for %v\n", "%", Glob.GetProblemName()) } -func (ps *OutputProofStruct) printProofWithProofStruct(finalProof []ProofStruct, metaList Lib.Set[AST.Meta]) { +func (ps *OutputProofStruct) printProofWithProofStruct( + finalProof []ProofStruct, + metaList Lib.Set[AST.Meta], +) { output := ps.ProofOutput(finalProof, metaList.Elements()) if Glob.GetWriteLogs() { diff --git a/src/Search/proof.go b/src/Search/proof.go index 6a3a5e27..88a97e04 100644 --- a/src/Search/proof.go +++ b/src/Search/proof.go @@ -149,14 +149,28 @@ func IntFormAndTermsListListToString(fll []IntFormAndTermsList) string { } func (p ProofStruct) ToString() string { - res := "(" + strconv.Itoa(p.GetNodeId()) + ")" + p.GetFormula().ToString() + " - " + p.GetRule() + " - " + IntFormAndTermsListListToString(p.GetResultFormulas()) + res := "(" + strconv.Itoa( + p.GetNodeId(), + ) + ")" + p.GetFormula(). + ToString() + + " - " + p.GetRule() + " - " + IntFormAndTermsListListToString( + p.GetResultFormulas(), + ) if len(p.GetChildren()) > 0 { res += " - " + ProofChildrenToString(p.GetChildren()) } return res } func (p ProofStruct) Copy() ProofStruct { - return ProofStruct{p.GetFormula(), p.GetIdDMT(), p.GetNodeId(), p.GetRule(), p.GetRuleName(), p.GetResultFormulas(), copyProofStructChildren(p.Children)} + return ProofStruct{ + p.GetFormula(), + p.GetIdDMT(), + p.GetNodeId(), + p.GetRule(), + p.GetRuleName(), + p.GetResultFormulas(), + copyProofStructChildren(p.Children), + } } func ProofStructListToString(l []ProofStruct) string { @@ -249,7 +263,13 @@ func MakeEmptyProofStruct() ProofStruct { } } -func MakeProofStruct(formula Core.FormAndTerms, formula_use, id int, rule, rule_name string, Result_formulas []IntFormAndTermsList, children [][]ProofStruct) ProofStruct { +func MakeProofStruct( + formula Core.FormAndTerms, + formula_use, id int, + rule, rule_name string, + Result_formulas []IntFormAndTermsList, + children [][]ProofStruct, +) ProofStruct { return ProofStruct{formula, formula_use, id, rule, rule_name, Result_formulas, children} } @@ -286,7 +306,15 @@ func IntFormAndTermsListToIntIntStringPairList(fl []IntFormAndTermsList) []IntIn func ProofStructListToJsonProofStructList(ps []ProofStruct) []JsonProofStruct { res := []JsonProofStruct{} for _, p := range ps { - new_json_element := JsonProofStruct{p.GetFormula().GetForm().ToMappedString(AST.DefaultMapString, Glob.GetTypeProof()), p.GetIdDMT(), p.Node_id, p.Rule, p.Rule_name, IntFormAndTermsListToIntIntStringPairList(p.Result_formulas), proofStructChildrenToJsonProofStructChildren(p.Children)} + new_json_element := JsonProofStruct{ + p.GetFormula().GetForm().ToMappedString(AST.DefaultMapString, Glob.GetTypeProof()), + p.GetIdDMT(), + p.Node_id, + p.Rule, + p.Rule_name, + IntFormAndTermsListToIntIntStringPairList(p.Result_formulas), + proofStructChildrenToJsonProofStructChildren(p.Children), + } res = append(res, new_json_element) } return res @@ -412,7 +440,13 @@ func ApplySubstitutionOnProofList(s Unif.Substitutions, proof_list []ProofStruct new_result_formulas := []IntFormAndTermsList{} for _, f := range p.GetResultFormulas() { - new_result_formulas = append(new_result_formulas, MakeIntFormAndTermsList(f.GetI(), Core.ApplySubstitutionsOnFormAndTermsList(s, f.GetFL()))) + new_result_formulas = append( + new_result_formulas, + MakeIntFormAndTermsList( + f.GetI(), + Core.ApplySubstitutionsOnFormAndTermsList(s, f.GetFL()), + ), + ) } p.SetResultFormulasProof(new_result_formulas) diff --git a/src/Search/rules.go b/src/Search/rules.go index a2f653dc..ce0b06ef 100644 --- a/src/Search/rules.go +++ b/src/Search/rules.go @@ -38,12 +38,13 @@ package Search import ( "fmt" + "os" + "github.com/GoelandProver/Goeland/AST" "github.com/GoelandProver/Goeland/Core" "github.com/GoelandProver/Goeland/Glob" "github.com/GoelandProver/Goeland/Lib" "github.com/GoelandProver/Goeland/Unif" - "os" ) var strToPrintMap map[string]string = map[string]string{ @@ -70,7 +71,10 @@ var strToPrintMap map[string]string = map[string]string{ * a boolean, true if a contradiction was found, false otherwise * a substitution, the substitution which make the contradiction (possibly empty) **/ -func ApplyClosureRules(form AST.Form, state *State) (result bool, substitutions []Unif.Substitutions) { +func ApplyClosureRules( + form AST.Form, + state *State, +) (result bool, substitutions []Unif.Substitutions) { debug(Lib.MkLazy(func() string { return "Start ACR" })) if searchObviousClosureRule(form) { @@ -173,15 +177,21 @@ func searchInequalities(form AST.Form) (bool, Unif.Substitutions) { arg_2 := predNeq.GetArgs().At(1) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Arg 1 : %v", arg_1.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Arg 1 : %v", arg_1.ToString()) }, + ), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Arg 2 : %v", arg_2.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Arg 2 : %v", arg_2.ToString()) }, + ), ) subst = Unif.AddUnification(arg_1, arg_2, subst) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Subst : %v", subst.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Subst : %v", subst.ToString()) }, + ), ) if !subst.Equals(Unif.Failure()) { @@ -290,7 +300,9 @@ func applyAlphaNotOrRule( setStateRules(state, "ALPHA", "NOT", "OR") for i := range formWithoutNot.FormList.Slice() { - result = result.AppendIfNotContains(Core.MakeFormAndTerm(AST.MakerNot(formWithoutNot.FormList.Get(i)), terms)) + result = result.AppendIfNotContains( + Core.MakeFormAndTerm(AST.MakerNot(formWithoutNot.FormList.Get(i)), terms), + ) } return result @@ -305,7 +317,9 @@ func applyAlphaNotImpRule( setStateRules(state, "ALPHA", "NOT", "IMPLY") result = result.AppendIfNotContains(Core.MakeFormAndTerm(formWithoutNot.GetF1(), terms)) - result = result.AppendIfNotContains(Core.MakeFormAndTerm(AST.MakerNot(formWithoutNot.GetF2()), terms)) + result = result.AppendIfNotContains( + Core.MakeFormAndTerm(AST.MakerNot(formWithoutNot.GetF2()), terms), + ) return result } @@ -378,7 +392,12 @@ func applyBetaNotAndRule( setStateRules(state, "BETA", "NOT", "AND") for i := range formWithoutNot.FormList.Slice() { - result = append(result, Core.MakeSingleElementFormAndTermList(Core.MakeFormAndTerm(AST.MakerNot(formWithoutNot.FormList.Get(i)), terms))) + result = append( + result, + Core.MakeSingleElementFormAndTermList( + Core.MakeFormAndTerm(AST.MakerNot(formWithoutNot.FormList.Get(i)), terms), + ), + ) } return result @@ -413,7 +432,12 @@ func applyBetaOrRule( setStateRules(state, "BETA", "OR") for i := range formTyped.FormList.Slice() { - result = append(result, Core.MakeSingleElementFormAndTermList(Core.MakeFormAndTerm(formTyped.FormList.Get(i), terms))) + result = append( + result, + Core.MakeSingleElementFormAndTermList( + Core.MakeFormAndTerm(formTyped.FormList.Get(i), terms), + ), + ) } return result @@ -427,8 +451,16 @@ func applyBetaImpRule( ) []Core.FormAndTermsList { setStateRules(state, "BETA", "IMPLY") - result = append(result, Core.MakeSingleElementFormAndTermList(Core.MakeFormAndTerm(AST.MakerNot(formTyped.GetF1()), terms))) - result = append(result, Core.MakeSingleElementFormAndTermList(Core.MakeFormAndTerm(formTyped.GetF2(), terms))) + result = append( + result, + Core.MakeSingleElementFormAndTermList( + Core.MakeFormAndTerm(AST.MakerNot(formTyped.GetF1()), terms), + ), + ) + result = append( + result, + Core.MakeSingleElementFormAndTermList(Core.MakeFormAndTerm(formTyped.GetF2(), terms)), + ) return result } @@ -488,7 +520,11 @@ func ApplyDeltaRules(fnt Core.FormAndTerms, state *State) Core.FormAndTermsList * a formula * the new metavariables **/ -func ApplyGammaRules(fnt Core.FormAndTerms, index int, state *State) (Core.FormAndTermsList, Lib.Set[AST.Meta]) { +func ApplyGammaRules( + fnt Core.FormAndTerms, + index int, + state *State, +) (Core.FormAndTermsList, Lib.Set[AST.Meta]) { switch fnt.GetForm().(type) { case AST.Not: setStateRules(state, "GAMMA", "NOT", "EXISTS") diff --git a/src/Search/search.go b/src/Search/search.go index cb5e019b..ae718377 100644 --- a/src/Search/search.go +++ b/src/Search/search.go @@ -49,7 +49,15 @@ import ( type SearchAlgorithm interface { Search(AST.Form, int) bool SetApplyRules(func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int)) - ManageClosureRule(uint64, *State, Communication, []Unif.Substitutions, Core.FormAndTerms, int, int) (bool, []Core.SubstAndForm) + ManageClosureRule( + uint64, + *State, + Communication, + []Unif.Substitutions, + Core.FormAndTerms, + int, + int, + ) (bool, []Core.SubstAndForm) } var UsedSearch SearchAlgorithm @@ -70,7 +78,9 @@ func SetSearchAlgorithm(algo SearchAlgorithm) { UsedSearch = algo } -func SetApplyRules(function func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int)) { +func SetApplyRules( + function func(uint64, State, Communication, Core.FormAndTermsList, int, int, []int), +) { UsedSearch.SetApplyRules(function) } diff --git a/src/Search/search_test.go b/src/Search/search_test.go index b869aad1..240da3be 100644 --- a/src/Search/search_test.go +++ b/src/Search/search_test.go @@ -40,6 +40,7 @@ import ( "os" "testing" + "github.com/GoelandProver/Goeland/AST" "github.com/GoelandProver/Goeland/Core" "github.com/GoelandProver/Goeland/Typing" ) @@ -57,7 +58,13 @@ func TestMain(m *testing.M) { func TestSimpleExistSkolemization(t *testing.T) { // exists x. P(x) ==> x should be a new constant expression x := Core.MakerVar("x") - form := Core.MakeFormAndTerm(Core.MakerEx([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{})), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerEx( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + Core.NewTermList(), + ) f := Core.Skolemize(form, Core.NewMetaList()) if pred, ok := f.GetForm().(AST.Pred); ok { @@ -84,7 +91,15 @@ func TestSimpleExistSkolemization(t *testing.T) { func TestSimpleNotForallSkolemization(t *testing.T) { // not(forall x. P(x)) ==> x should be a new constant expression x := Core.MakerVar("x") - form := Core.MakeFormAndTerm(Core.MakerNot(Core.MakerAll([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}))), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerNot( + Core.MakerAll( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + ), + Core.NewTermList(), + ) f := Core.Skolemize(form, Core.NewMetaList()) if neg, ok := f.GetForm().(AST.Not); ok { @@ -115,7 +130,13 @@ func TestSimpleNotForallSkolemization(t *testing.T) { func TestSimpleForallInstantiation(t *testing.T) { // forall x. P(x) ==> x should be a new meta x := Core.MakerVar("x") - form := Core.MakeFormAndTerm(Core.MakerAll([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{})), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerAll( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + Core.NewTermList(), + ) f, metas := Core.Instantiate(form, 0) if metas.Len() != 1 { @@ -146,7 +167,15 @@ func TestSimpleForallInstantiation(t *testing.T) { func TestSimpleNotExistsInstantiation(t *testing.T) { // neg(exists x. P(x)) ==> x should be a new meta x := Core.MakerVar("x") - form := Core.MakeFormAndTerm(Core.MakerNot(Core.MakerEx([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}))), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerNot( + Core.MakerEx( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + ), + Core.NewTermList(), + ) f, metas := Core.Instantiate(form, 0) if metas.Len() != 1 { @@ -184,7 +213,13 @@ func TestSimpleTypedExistSkolemization(t *testing.T) { tInt := polymorphism.MkTypeHint("int") // exists x. P(x) ==> x should be a new constant expression x := Core.MakerVar("x", tInt) - form := Core.MakeFormAndTerm(Core.MakerEx([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{})), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerEx( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + Core.NewTermList(), + ) f := Core.Skolemize(form, Core.NewMetaList()) if pred, ok := f.GetForm().(AST.Pred); ok { @@ -212,7 +247,15 @@ func TestSimpleTypedNotForallSkolemization(t *testing.T) { tInt := polymorphism.MkTypeHint("int") // not(forall x. P(x)) ==> x should be a new constant expression x := Core.MakerVar("x", tInt) - form := Core.MakeFormAndTerm(Core.MakerNot(Core.MakerAll([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}))), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerNot( + Core.MakerAll( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + ), + Core.NewTermList(), + ) f := Core.Skolemize(form, Core.NewMetaList()) if neg, ok := f.GetForm().(AST.Not); ok { @@ -244,7 +287,13 @@ func TestSimpleTypedForallInstantiation(t *testing.T) { tInt := polymorphism.MkTypeHint("int") // forall x. P(x) ==> x should be a new meta x := Core.MakerVar("x", tInt) - form := Core.MakeFormAndTerm(Core.MakerAll([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{})), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerAll( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + Core.NewTermList(), + ) f, metas := Core.Instantiate(form, 0) if metas.Len() != 1 { @@ -276,7 +325,15 @@ func TestSimpleTypedNotExistsInstantiation(t *testing.T) { tInt := polymorphism.MkTypeHint("int") // neg(exists x. P(x)) ==> x should be a new meta x := Core.MakerVar("x", tInt) - form := Core.MakeFormAndTerm(Core.MakerNot(Core.MakerEx([]Core.Var{x}, Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}))), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerNot( + Core.MakerEx( + []Core.Var{x}, + Core.MakerPred(Core.MakerId("P"), Core.NewTermList(x), []polymorphism.TypeApp{}), + ), + ), + Core.NewTermList(), + ) f, metas := Core.Instantiate(form, 0) if metas.Len() != 1 { @@ -314,7 +371,30 @@ func TestSyntaxicTransformationOnFormula(t *testing.T) { // Formula definition vars := []Core.Var{Core.MakerVar("x"), Core.MakerVar("y"), Core.MakerVar("z")} // forall x. P(x) => forall y. exists z.R(z, y) - form := Core.MakeFormAndTerm(Core.MakerAll([]Core.Var{vars[0]}, Core.MakerImp(Core.MakerPred(Core.MakerId("P"), Core.NewTermList(vars[0]), []polymorphism.TypeApp{}), Core.MakerAll([]Core.Var{vars[1]}, Core.MakerEx([]Core.Var{vars[2]}, Core.MakerPred(Core.MakerId("R"), Core.NewTermList(vars[2], vars[1]), []polymorphism.TypeApp{}))))), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerAll( + []Core.Var{vars[0]}, + Core.MakerImp( + Core.MakerPred( + Core.MakerId("P"), + Core.NewTermList(vars[0]), + []polymorphism.TypeApp{}, + ), + Core.MakerAll( + []Core.Var{vars[1]}, + Core.MakerEx( + []Core.Var{vars[2]}, + Core.MakerPred( + Core.MakerId("R"), + Core.NewTermList(vars[2], vars[1]), + []polymorphism.TypeApp{}, + ), + ), + ), + ), + ), + Core.NewTermList(), + ) // Instantiate x f1_inst, metas := Core.Instantiate(form, 0) @@ -326,7 +406,13 @@ func TestSyntaxicTransformationOnFormula(t *testing.T) { } // Skolemize y & Instantiate z - f2_inst, metas_2 := Core.Instantiate(Core.MakeFormAndTerm(form.GetForm().(AST.All).GetForm().(AST.Imp).GetF2(), Core.NewTermList()), 0) + f2_inst, metas_2 := Core.Instantiate( + Core.MakeFormAndTerm( + form.GetForm().(AST.All).GetForm().(AST.Imp).GetF2(), + Core.NewTermList(), + ), + 0, + ) metas.AppendIfNotContains(metas_2.Slice()...) f2_sko := Core.Skolemize(f2_inst, Core.NewMetaList()) @@ -361,7 +447,31 @@ func TestSyntaxicTransformationOnTypedFormula(t *testing.T) { // Formula definition vars := []Core.Var{Core.MakerVar("x", tInt), Core.MakerVar("y", tInt), Core.MakerVar("z", tInt)} // forall x. P(x) => forall y. exists z.R(z, y) - form := Core.MakeFormAndTerm(Core.MakerAll([]Core.Var{vars[0]}, Core.MakerImp(Core.MakerPred(Core.MakerId("P"), Core.NewTermList(vars[0]), []polymorphism.TypeApp{}), Core.MakerAll([]Core.Var{vars[1]}, Core.MakerEx([]Core.Var{vars[2]}, Core.MakerPred(Core.MakerId("R"), Core.NewTermList(vars[2], vars[1]), []polymorphism.TypeApp{}, polymorphism.MkTypeArrow(polymorphism.MkTypeCross(tInt, tInt), tProp)))))), Core.NewTermList()) + form := Core.MakeFormAndTerm( + Core.MakerAll( + []Core.Var{vars[0]}, + Core.MakerImp( + Core.MakerPred( + Core.MakerId("P"), + Core.NewTermList(vars[0]), + []polymorphism.TypeApp{}, + ), + Core.MakerAll( + []Core.Var{vars[1]}, + Core.MakerEx( + []Core.Var{vars[2]}, + Core.MakerPred( + Core.MakerId("R"), + Core.NewTermList(vars[2], vars[1]), + []polymorphism.TypeApp{}, + polymorphism.MkTypeArrow(polymorphism.MkTypeCross(tInt, tInt), tProp), + ), + ), + ), + ), + ), + Core.NewTermList(), + ) // Instantiate x f1_inst, metas := Core.Instantiate(form, 0) @@ -373,7 +483,13 @@ func TestSyntaxicTransformationOnTypedFormula(t *testing.T) { } // Skolemize y & Instantiate z - f2_inst, metas_2 := Core.Instantiate(Core.MakeFormAndTerm(form.GetForm().(AST.All).GetForm().(AST.Imp).GetF2(), Core.NewTermList()), 0) + f2_inst, metas_2 := Core.Instantiate( + Core.MakeFormAndTerm( + form.GetForm().(AST.All).GetForm().(AST.Imp).GetF2(), + Core.NewTermList(), + ), + 0, + ) metas.AppendIfNotContains(metas_2.Slice()...) f2_sko := Core.Skolemize(f2_inst, Core.NewMetaList()) diff --git a/src/Search/state.go b/src/Search/state.go index 9015e430..c2ac276e 100644 --- a/src/Search/state.go +++ b/src/Search/state.go @@ -353,7 +353,9 @@ func (st State) Print() { debug(Lib.MkLazy(func() string { return "Subst_found: " })) debug( Lib.MkLazy(func() string { - return Unif.SubstListToString(Core.GetSubstListFromSubstAndFormList(st.GetSubstsFound())) + return Unif.SubstListToString( + Core.GetSubstListFromSubstAndFormList(st.GetSubstsFound()), + ) }), ) } @@ -369,7 +371,9 @@ func (st State) Print() { } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("BT on formulas : %v", st.GetBTOnFormulas()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("BT on formulas : %v", st.GetBTOnFormulas()) }, + ), ) } @@ -456,14 +460,18 @@ func (st State) CanApplyGammaRule() bool { /* Check if rules are appliable */ func (st State) AreRulesApplicable() bool { - return len(st.GetAlpha()) > 0 || len(st.GetDelta()) > 0 || len(st.GetBeta()) > 0 || (len(st.GetGamma()) > 0 && st.CanApplyGammaRule()) || (Glob.IsDestructive() && len(st.GetMetaGen()) > 0) + return len(st.GetAlpha()) > 0 || len(st.GetDelta()) > 0 || len(st.GetBeta()) > 0 || + (len(st.GetGamma()) > 0 && st.CanApplyGammaRule()) || + (Glob.IsDestructive() && len(st.GetMetaGen()) > 0) } /* Put the given formula in the right rule box in the given state */ func (st *State) DispatchForm(f Core.FormAndTerms) { debug(Lib.MkLazy(func() string { return fmt.Sprintf("Dispatch the form : %v ", f.ToString()) })) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Kind of rule : %v ", Core.ShowKindOfRule(f.GetForm())) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Kind of rule : %v ", Core.ShowKindOfRule(f.GetForm())) }, + ), ) switch Core.ShowKindOfRule(f.GetForm()) { case Core.Atomic: diff --git a/src/Tests/DMT/equ_test.go b/src/Tests/DMT/equ_test.go index 63ff4fb4..c57f1913 100644 --- a/src/Tests/DMT/equ_test.go +++ b/src/Tests/DMT/equ_test.go @@ -95,7 +95,10 @@ func TestEquRegistration(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -108,7 +111,10 @@ func TestEquRegistration(t *testing.T) { // P(a) <=> forall y.Q(a, y) equPred2 := basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}), + ), ) if !dmt.RegisterAxiom(equPred2) { @@ -127,7 +133,10 @@ func TestEquRegistration(t *testing.T) { ) if dmt.RegisterAxiom(equPred3) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (the two formulas are atomic).", equPred3.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (the two formulas are atomic).", + equPred3.ToString(), + ) } // The right-side is atomic, and not the left ! @@ -136,7 +145,10 @@ func TestEquRegistration(t *testing.T) { equPred4 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerImp(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), basictypes.MakerPred(Q, basictypes.NewTermList(x, a), []typing.TypeApp{})), + basictypes.MakerImp( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + basictypes.MakerPred(Q, basictypes.NewTermList(x, a), []typing.TypeApp{}), + ), basictypes.MakerPred(Q, basictypes.NewTermList(a, x), []typing.TypeApp{}), ), ) @@ -151,7 +163,10 @@ func TestEquRegistration(t *testing.T) { equPred5 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), ), ) @@ -175,7 +190,10 @@ func TestEquRegistration(t *testing.T) { ) if dmt.RegisterAxiom(equPred6) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", equPred6.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + equPred6.ToString(), + ) } // Negative atom @@ -184,8 +202,13 @@ func TestEquRegistration(t *testing.T) { equPred7 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.RefuteForm(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.RefuteForm( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -199,8 +222,15 @@ func TestEquRegistration(t *testing.T) { equPred8 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.RefuteForm(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.RefuteForm(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}))), + basictypes.RefuteForm( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.RefuteForm( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), + ), ), ) @@ -209,35 +239,66 @@ func TestEquRegistration(t *testing.T) { } // (x = x) => forall x. P(x) shouldn't be registered (because equality and dmt are managed separately) - neqPred := basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}) + neqPred := basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, x), + []typing.TypeApp{}, + ) eqPred9 := basictypes.MakerEqu( neqPred, - basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), ) if dmt.RegisterAxiom(eqPred9) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", eqPred9.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + eqPred9.ToString(), + ) } // (Vx (x = x)) => forall x. P(x) shouldn't be registered - neqPred2 := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})) + neqPred2 := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) eqPred10 := basictypes.MakerEqu( neqPred2, - basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), ) if dmt.RegisterAxiom(eqPred10) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", eqPred10.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + eqPred10.ToString(), + ) } // forall x.¬(x = x) <=> forall y. Q(x, y) shouldn't be registered eqPred11 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerNot( + basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, x), + []typing.TypeApp{}, + ), + ), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) if dmt.RegisterAxiom(eqPred11) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", eqPred11.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + eqPred11.ToString(), + ) } } @@ -248,10 +309,16 @@ func TestEquRegistration(t *testing.T) { func TestSimpleAxiomRegistration(t *testing.T) { initDMT() // forall x.P(x) - simplePred := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})) + simplePred := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(simplePred) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", simplePred.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + simplePred.ToString(), + ) } // If it's a fact, it shouldn't be registered @@ -260,28 +327,51 @@ func TestSimpleAxiomRegistration(t *testing.T) { simplePred2 := basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}) if dmt.RegisterAxiom(simplePred2) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (a fact has to be kept).", simplePred2.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (a fact has to be kept).", + simplePred2.ToString(), + ) } // forall x.¬P(x) - simplePred3 := basictypes.MakerAll([]basictypes.Var{x}, basictypes.RefuteForm(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}))) + simplePred3 := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.RefuteForm( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + ) if dmt.RegisterAxiom(simplePred3) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", simplePred3.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + simplePred3.ToString(), + ) } // a = b shouldn't be registered (because equality and dmt are managed separately) - eqPred := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})) + eqPred := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(eqPred) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", eqPred.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + eqPred.ToString(), + ) } // a != b shouldn't be registered (because equality and dmt are managed separately) - neqPred := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})) + neqPred := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(neqPred) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", neqPred.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + neqPred.ToString(), + ) } } @@ -295,12 +385,18 @@ func TestImpRegistration(t *testing.T) { []basictypes.Var{x}, basictypes.MakerImp( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) if dmt.RegisterAxiom(impPred) { - t.Fatalf("Error: %s has been registered as a rewrite rule when polarization isn't activated.", impPred.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when polarization isn't activated.", + impPred.ToString(), + ) } } @@ -318,7 +414,10 @@ func TestEquRewrite1(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -334,19 +433,30 @@ func TestEquRewrite1(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } - if !forms.Get(0).Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || + if !forms.Get(0). + Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || subst.GetMeta().Len() > 0 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -360,7 +470,10 @@ func TestEquRewrite2(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -368,7 +481,9 @@ func TestEquRewrite2(t *testing.T) { t.Fatalf("Error: %s hasn't been registered as a rewrite rule.", equPred.ToString()) } - form := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + form := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) substs, err := dmt.Rewrite(form) if err != nil { @@ -376,19 +491,30 @@ func TestEquRewrite2(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } - if !forms.Get(0).Equals(basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})))) || + if !forms.Get(0). + Equals(basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})))) || subst.GetMeta().Len() > 0 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -401,8 +527,13 @@ func TestEquRewrite3(t *testing.T) { equPred := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -418,19 +549,30 @@ func TestEquRewrite3(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } - if !forms.Get(0).Equals(basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})))) || + if !forms.Get(0). + Equals(basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})))) || subst.GetMeta().Len() > 0 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -443,8 +585,13 @@ func TestEquRewrite4(t *testing.T) { equPred := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -452,7 +599,9 @@ func TestEquRewrite4(t *testing.T) { t.Fatalf("Error: %s hasn't been registered as a rewrite rule.", equPred.ToString()) } - form := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + form := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) substs, err := dmt.Rewrite(form) if err != nil { @@ -460,19 +609,30 @@ func TestEquRewrite4(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } - if !forms.Get(0).Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || + if !forms.Get(0). + Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || subst.GetMeta().Len() > 0 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -485,8 +645,15 @@ func TestEquRewrite5(t *testing.T) { equPred := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}))), + basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerNot( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), + ), ), ) @@ -502,19 +669,30 @@ func TestEquRewrite5(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } - if !forms.Get(0).Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || + if !forms.Get(0). + Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || subst.GetMeta().Len() > 0 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -527,8 +705,15 @@ func TestEquRewrite6(t *testing.T) { equPred := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerEqu( - basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}))), + basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerNot( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), + ), ), ) @@ -536,7 +721,9 @@ func TestEquRewrite6(t *testing.T) { t.Fatalf("Error: %s hasn't been registered as a rewrite rule.", equPred.ToString()) } - form := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + form := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) substs, err := dmt.Rewrite(form) if err != nil { @@ -544,19 +731,30 @@ func TestEquRewrite6(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } - if !forms.Get(0).Equals(basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})))) || + if !forms.Get(0). + Equals(basictypes.MakerNot(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})))) || subst.GetMeta().Len() > 0 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -571,7 +769,12 @@ func TestSubst1(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x, x), []typing.TypeApp{}), - basictypes.MakerAnd(basictypes.NewFormList(basictypes.MakerPred(Q, basictypes.NewTermList(x, x), []typing.TypeApp{}), basictypes.MakerPred(P, basictypes.NewTermList(x, x), []typing.TypeApp{}))), + basictypes.MakerAnd( + basictypes.NewFormList( + basictypes.MakerPred(Q, basictypes.NewTermList(x, x), []typing.TypeApp{}), + basictypes.MakerPred(P, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ), + ), ), ) global.PrintDebug( @@ -598,7 +801,10 @@ func TestSubst1(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } global.PrintDebug( @@ -609,13 +815,20 @@ func TestSubst1(t *testing.T) { subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } if !(forms.Get(0).Equals(basictypes.MakerAnd(basictypes.NewFormList(basictypes.MakerPred(Q, basictypes.NewTermList(Y, Y), []typing.TypeApp{}), basictypes.MakerPred(P, basictypes.NewTermList(Y, Y), []typing.TypeApp{})))) || forms.Get(0).Equals(basictypes.MakerAnd(basictypes.NewFormList(basictypes.MakerPred(Q, basictypes.NewTermList(Z, Z), []typing.TypeApp{}), basictypes.MakerPred(P, basictypes.NewTermList(Z, Z), []typing.TypeApp{}))))) || len(subst) != 1 { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -627,7 +840,10 @@ func TestSubst2(t *testing.T) { // P(a) <=> forall y.Q(a, y) equPred := basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}), + ), ) if !dmt.RegisterAxiom(equPred) { @@ -644,21 +860,32 @@ func TestSubst2(t *testing.T) { } if len(substs) > 1 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() subst := substs[0].GetSaf().GetSubst() if forms.Len() > 1 { - t.Fatalf("Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than one formula when it should be rewritten by only one.", + form.ToString(), + ) } Y, _ := subst.Get(X) - if !forms.Get(0).Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || + if !forms.Get(0). + Equals(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || !(len(subst) == 1 && Y.Equals(a)) { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.Get(0).ToString(), + ) } } @@ -667,8 +894,20 @@ func TestSubst3(t *testing.T) { axiom := basictypes.MakerAll( []basictypes.Var{x, y}, basictypes.MakerEqu( - basictypes.MakerPred(P, basictypes.NewTermList(x, basictypes.MakerFun(f, basictypes.NewTermList(y), []typing.TypeApp{})), []typing.TypeApp{}), - basictypes.MakerAnd(basictypes.NewFormList(basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}))), + basictypes.MakerPred( + P, + basictypes.NewTermList( + x, + basictypes.MakerFun(f, basictypes.NewTermList(y), []typing.TypeApp{}), + ), + []typing.TypeApp{}, + ), + basictypes.MakerAnd( + basictypes.NewFormList( + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), + ), ), ) @@ -687,7 +926,12 @@ func TestSubst3(t *testing.T) { } if len(substs) != 1 && !substs[0].GetSaf().GetSubst().Equals(treetypes.Failure()) { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s - %v.", form.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString(), substs[0].GetSaf().GetSubst().ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s - %v.", + form.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + substs[0].GetSaf().GetSubst().ToString(), + ) } } @@ -700,12 +944,18 @@ func TestMultipleAxiomDefinition(t *testing.T) { // P(a) <=> forall y.Q(a, y) equPred := basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}), + ), ) // P(a) <=> forall y.Q(y, a) equPred2 := basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(y, a), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(y, a), []typing.TypeApp{}), + ), ) if !dmt.RegisterAxiom(equPred) { @@ -723,19 +973,39 @@ func TestMultipleAxiomDefinition(t *testing.T) { } if len(substs) != 2 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() forms.Append(substs[1].GetSaf().GetForm().Slice()...) if forms.Len() != 2 { - t.Fatalf("Error: %s can be rewritten by more than two formulas when it should be rewritten by only two.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than two formulas when it should be rewritten by only two.", + form.ToString(), + ) } - if !forms.Contains(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || - !forms.Contains(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(y, a), []typing.TypeApp{}))) { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.ToString()) + if !forms.Contains( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}), + ), + ) || + !forms.Contains( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(y, a), []typing.TypeApp{}), + ), + ) { + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.ToString(), + ) } } @@ -746,7 +1016,10 @@ func TestMultipleAxiomDefinition2(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) // P(a) <=> forall y.Q(y, a) @@ -754,7 +1027,10 @@ func TestMultipleAxiomDefinition2(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(y, x), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(y, x), []typing.TypeApp{}), + ), ), ) @@ -773,19 +1049,39 @@ func TestMultipleAxiomDefinition2(t *testing.T) { } if len(substs) != 2 { - t.Fatalf("Error: more than one rewrite rule found for %s when it should have only one.", form.ToString()) + t.Fatalf( + "Error: more than one rewrite rule found for %s when it should have only one.", + form.ToString(), + ) } forms := substs[0].GetSaf().GetForm() forms.Append(substs[1].GetSaf().GetForm().Slice()...) if forms.Len() != 2 { - t.Fatalf("Error: %s can be rewritten by more than two formulas when it should be rewritten by only two.", form.ToString()) + t.Fatalf( + "Error: %s can be rewritten by more than two formulas when it should be rewritten by only two.", + form.ToString(), + ) } - if !forms.Contains(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}))) || - !forms.Contains(basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(y, a), []typing.TypeApp{}))) { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), forms.ToString()) + if !forms.Contains( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(a, y), []typing.TypeApp{}), + ), + ) || + !forms.Contains( + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(y, a), []typing.TypeApp{}), + ), + ) { + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + forms.ToString(), + ) } } @@ -815,7 +1111,10 @@ func TestSort(t *testing.T) { []basictypes.Var{x}, basictypes.MakerEqu( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -823,10 +1122,16 @@ func TestSort(t *testing.T) { t.Fatalf("Error: %s hasn't been registered as a rewrite rule.", equPred.ToString()) } - axiom := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})) + axiom := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + axiom.ToString(), + ) } // forall x.P(x) and forall x.P(x) <=> forall y.Q(x, y) are in the rewrite tree. diff --git a/src/Tests/DMT/pol_test.go b/src/Tests/DMT/pol_test.go index 84dabcfe..a3c62bf2 100644 --- a/src/Tests/DMT/pol_test.go +++ b/src/Tests/DMT/pol_test.go @@ -61,7 +61,10 @@ func TestPolarizedInsertion(t *testing.T) { []basictypes.Var{x}, basictypes.MakerImp( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -84,7 +87,10 @@ func TestPolarizedInsertion(t *testing.T) { polPred3 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerImp( - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), ), ) @@ -94,12 +100,21 @@ func TestPolarizedInsertion(t *testing.T) { } polPred4 := basictypes.MakerImp( - basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerAll([]basictypes.Var{x, y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerAll( + []basictypes.Var{x, y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ) if dmt.RegisterAxiom(polPred4) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't be.", polPred4.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't be.", + polPred4.ToString(), + ) } polPred5 := basictypes.MakerImp( @@ -114,8 +129,12 @@ func TestPolarizedInsertion(t *testing.T) { polPred6 := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerImp( - basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerNot(basictypes.MakerPred(Q, basictypes.NewTermList(x, a), []typing.TypeApp{})), + basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerNot( + basictypes.MakerPred(Q, basictypes.NewTermList(x, a), []typing.TypeApp{}), + ), ), ) @@ -124,23 +143,42 @@ func TestPolarizedInsertion(t *testing.T) { } // (x = x) => forall x. P(x) shouldn't be registered (because equality and dmt are managed separately) - neqPred := basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}) + neqPred := basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, x), + []typing.TypeApp{}, + ) polPred7 := basictypes.MakerImp( neqPred, - basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), ) if dmt.RegisterAxiom(polPred7) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", polPred7.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + polPred7.ToString(), + ) } // (Vx (x = x)) => forall x. P(x) shouldn't be registered - neqPred2 := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})) + neqPred2 := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) polPred8 := basictypes.MakerImp( neqPred2, - basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), ) if dmt.RegisterAxiom(polPred8) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", polPred8.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't (equalities are not registered).", + polPred8.ToString(), + ) } polPred9 := basictypes.MakerAll( @@ -171,7 +209,10 @@ func TestPolarizedRewrite1(t *testing.T) { []basictypes.Var{x}, basictypes.MakerImp( basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), - basictypes.MakerAll([]basictypes.Var{y}, basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{})), + basictypes.MakerAll( + []basictypes.Var{y}, + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), ), ) @@ -184,7 +225,10 @@ func TestPolarizedRewrite1(t *testing.T) { substs, err := dmt.Rewrite(form) if err != nil { - t.Fatalf("Error: %s not found in the rewrite tree when it should have been.", form.ToString()) + t.Fatalf( + "Error: %s not found in the rewrite tree when it should have been.", + form.ToString(), + ) } expected := basictypes.MakerAll( @@ -196,10 +240,17 @@ func TestPolarizedRewrite1(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expected) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form.ToString(), expected.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form.ToString(), + expected.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } - form2 := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + form2 := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) substs, err = dmt.Rewrite(form2) if err != nil { @@ -247,7 +298,10 @@ func TestPolarizedRewrite2(t *testing.T) { substs, err := dmt.Rewrite(form) if err != nil { - t.Fatalf("Error: %s not found in the rewrite tree when it should have been.", form.ToString()) + t.Fatalf( + "Error: %s not found in the rewrite tree when it should have been.", + form.ToString(), + ) } expected := basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{}) @@ -256,10 +310,17 @@ func TestPolarizedRewrite2(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expected) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form.ToString(), expected.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form.ToString(), + expected.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } - form2 := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + form2 := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) substs, err = dmt.Rewrite(form2) if err != nil { @@ -272,20 +333,32 @@ func TestPolarizedRewrite2(t *testing.T) { // Only rewrites negative occurrences of Q - form3 := basictypes.MakerNot(basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{})) + form3 := basictypes.MakerNot( + basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{}), + ) substs, err = dmt.Rewrite(form3) if err != nil { - t.Fatalf("Error: %s not found in the rewrite tree when it should have been.", form3.ToString()) + t.Fatalf( + "Error: %s not found in the rewrite tree when it should have been.", + form3.ToString(), + ) } - expectedNeg := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + expectedNeg := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) if len(substs) > 1 || !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expectedNeg) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form3.ToString(), expectedNeg.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form3.ToString(), + expectedNeg.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } form4 := basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{}) @@ -309,8 +382,12 @@ func TestPolarizedRewrite3(t *testing.T) { polPred := basictypes.MakerAll( []basictypes.Var{x}, basictypes.MakerImp( - basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), - basictypes.MakerNot(basictypes.MakerPred(Q, basictypes.NewTermList(x, a), []typing.TypeApp{})), + basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ), + basictypes.MakerNot( + basictypes.MakerPred(Q, basictypes.NewTermList(x, a), []typing.TypeApp{}), + ), ), ) @@ -319,20 +396,32 @@ func TestPolarizedRewrite3(t *testing.T) { } // Only rewrites on negative occurrences of P - form := basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{})) + form := basictypes.MakerNot( + basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}), + ) substs, err := dmt.Rewrite(form) if err != nil { - t.Fatalf("Error: %s not found in the rewrite tree when it should have been.", form.ToString()) + t.Fatalf( + "Error: %s not found in the rewrite tree when it should have been.", + form.ToString(), + ) } - expected := basictypes.MakerNot(basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{})) + expected := basictypes.MakerNot( + basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{}), + ) if len(substs) > 1 || !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expected) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form.ToString(), expected.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form.ToString(), + expected.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } form2 := basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}) @@ -352,7 +441,10 @@ func TestPolarizedRewrite3(t *testing.T) { substs, err = dmt.Rewrite(form3) if err != nil { - t.Fatalf("Error: %s not found in the rewrite tree when it should have been.", form3.ToString()) + t.Fatalf( + "Error: %s not found in the rewrite tree when it should have been.", + form3.ToString(), + ) } expectedNeg := basictypes.MakerPred(P, basictypes.NewTermList(a), []typing.TypeApp{}) @@ -361,10 +453,17 @@ func TestPolarizedRewrite3(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expectedNeg) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form3.ToString(), expectedNeg.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form3.ToString(), + expectedNeg.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } - form4 := basictypes.MakerNot(basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{})) + form4 := basictypes.MakerNot( + basictypes.MakerPred(Q, basictypes.NewTermList(a, a), []typing.TypeApp{}), + ) substs, err = dmt.Rewrite(form4) if err != nil { @@ -385,8 +484,21 @@ func TestPolarizedRewrite4(t *testing.T) { axiom := basictypes.MakerAll( []basictypes.Var{x, y}, basictypes.MakerImp( - basictypes.MakerPred(P, basictypes.NewTermList(x, basictypes.MakerFun(f, basictypes.NewTermList(y), []typing.TypeApp{})), []typing.TypeApp{}), - basictypes.MakerAnd(basictypes.NewFormList(basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}))))) + basictypes.MakerPred( + P, + basictypes.NewTermList( + x, + basictypes.MakerFun(f, basictypes.NewTermList(y), []typing.TypeApp{}), + ), + []typing.TypeApp{}, + ), + basictypes.MakerAnd( + basictypes.NewFormList( + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + basictypes.MakerPred(Q, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ), + ), + )) if !dmt.RegisterAxiom(axiom) { t.Fatalf("Error: %s hasn't been registered as a rewrite rule.", axiom.ToString()) @@ -403,6 +515,11 @@ func TestPolarizedRewrite4(t *testing.T) { } if len(substs) != 1 && !substs[0].GetSaf().GetSubst().Equals(treetypes.Failure()) { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s - %v.", form.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString(), substs[0].GetSaf().GetSubst().ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s - %v.", + form.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + substs[0].GetSaf().GetSubst().ToString(), + ) } } diff --git a/src/Tests/DMT/sim_test.go b/src/Tests/DMT/sim_test.go index 450a1523..23f0e9c2 100644 --- a/src/Tests/DMT/sim_test.go +++ b/src/Tests/DMT/sim_test.go @@ -53,10 +53,16 @@ func TestAxiomRewriting(t *testing.T) { initDMT() // forall x.P(x) - axiom := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})) + axiom := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + axiom.ToString(), + ) } // Top @@ -97,10 +103,16 @@ func TestAxiomRewriting2(t *testing.T) { initDMT() // forall x.¬P(x) - axiom := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{}))) + axiom := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerNot(basictypes.MakerPred(P, basictypes.NewTermList(x), []typing.TypeApp{})), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + axiom.ToString(), + ) } // Bot @@ -141,10 +153,16 @@ func TestAxiomRewriting3(t *testing.T) { initDMT() // forall x.P(x) - axiom := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(P, basictypes.NewTermList(x, x), []typing.TypeApp{})) + axiom := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(P, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it shouldn't.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it shouldn't.", + axiom.ToString(), + ) } // X := basictypes.MakerMeta("X", 1) @@ -222,30 +240,66 @@ func TestAxiomRewriting4(t *testing.T) { initDMT() // forall x.x = x - axiom := basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})) + axiom := basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it's an equality.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it's an equality.", + axiom.ToString(), + ) } // forall x.x != x - axiom = basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{})) + axiom = basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it's an equality.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it's an equality.", + axiom.ToString(), + ) } // forall x.¬(x = x) - axiom = basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}))) + axiom = basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerNot( + basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, x), + []typing.TypeApp{}, + ), + ), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it's an equality.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it's an equality.", + axiom.ToString(), + ) } // forall x.¬(x != x) - axiom = basictypes.MakerAll([]basictypes.Var{x}, basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, x), []typing.TypeApp{}))) + axiom = basictypes.MakerAll( + []basictypes.Var{x}, + basictypes.MakerNot( + basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, x), + []typing.TypeApp{}, + ), + ), + ) if dmt.RegisterAxiom(axiom) { - t.Fatalf("Error: %s has been registered as a rewrite rule when it's an equality.", axiom.ToString()) + t.Fatalf( + "Error: %s has been registered as a rewrite rule when it's an equality.", + axiom.ToString(), + ) } } diff --git a/src/Tests/DMT/sko_test.go b/src/Tests/DMT/sko_test.go index 55aae0d7..d37b407a 100644 --- a/src/Tests/DMT/sko_test.go +++ b/src/Tests/DMT/sko_test.go @@ -98,11 +98,18 @@ func TestPreskolemization(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expected) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form.ToString(), expected.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form.ToString(), + expected.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } // Negative occurrences should be skolemized - form2 := basictypes.MakerNot(basictypes.MakerPred(subset, basictypes.NewTermList(a, b), []typing.TypeApp{})) + form2 := basictypes.MakerNot( + basictypes.MakerPred(subset, basictypes.NewTermList(a, b), []typing.TypeApp{}), + ) substs, err = dmt.Rewrite(form2) if err != nil { @@ -113,10 +120,22 @@ func TestPreskolemization(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || reflect.TypeOf(substs[0].GetSaf().GetForm().Get(0)) != reflect.TypeOf(basictypes.Not{}) || - reflect.TypeOf(substs[0].GetSaf().GetForm().Get(0).(basictypes.Not).GetForm()) != reflect.TypeOf(basictypes.Imp{}) || - !substs[0].GetSaf().GetForm().Get(0).(basictypes.Not).GetForm().(basictypes.Imp).GetF1().(basictypes.Pred).GetArgs().Get(0).IsFun() || - !substs[0].GetSaf().GetForm().Get(0).(basictypes.Not).GetForm().(basictypes.Imp).GetF2().(basictypes.Pred).GetArgs().Get(0).IsFun() { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form2.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + reflect.TypeOf( + substs[0].GetSaf().GetForm().Get(0).(basictypes.Not).GetForm(), + ) != reflect.TypeOf( + basictypes.Imp{}, + ) || + !substs[0].GetSaf().GetForm().Get(0).(basictypes.Not).GetForm().(basictypes.Imp).GetF1().(basictypes.Pred).GetArgs(). + Get(0). + IsFun() || + !substs[0].GetSaf().GetForm().Get(0).(basictypes.Not).GetForm().(basictypes.Imp).GetF2().(basictypes.Pred).GetArgs(). + Get(0). + IsFun() { + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form2.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } } @@ -159,13 +178,23 @@ func TestPreskolemization2(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || reflect.TypeOf(substs[0].GetSaf().GetForm().Get(0)) != reflect.TypeOf(basictypes.Imp{}) || - !substs[0].GetSaf().GetForm().Get(0).(basictypes.Imp).GetF1().(basictypes.Pred).GetArgs().Get(0).IsFun() || - !substs[0].GetSaf().GetForm().Get(0).(basictypes.Imp).GetF2().(basictypes.Pred).GetArgs().Get(0).IsFun() { - t.Fatalf("Error: %s has not been rewritten as expected. Actual: %s.", form.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + !substs[0].GetSaf().GetForm().Get(0).(basictypes.Imp).GetF1().(basictypes.Pred).GetArgs(). + Get(0). + IsFun() || + !substs[0].GetSaf().GetForm().Get(0).(basictypes.Imp).GetF2().(basictypes.Pred).GetArgs(). + Get(0). + IsFun() { + t.Fatalf( + "Error: %s has not been rewritten as expected. Actual: %s.", + form.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } // Negative occurrences should be rewritten normally - form2 := basictypes.MakerNot(basictypes.MakerPred(subset, basictypes.NewTermList(a, b), []typing.TypeApp{})) + form2 := basictypes.MakerNot( + basictypes.MakerPred(subset, basictypes.NewTermList(a, b), []typing.TypeApp{}), + ) substs, err = dmt.Rewrite(form2) if err != nil { @@ -184,6 +213,11 @@ func TestPreskolemization2(t *testing.T) { !substs[0].GetSaf().GetSubst().Equals(treetypes.MakeEmptySubstitution()) || substs[0].GetSaf().GetForm().Len() > 1 || !substs[0].GetSaf().GetForm().Get(0).Equals(expected) { - t.Fatalf("Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", form2.ToString(), expected.ToString(), substs[0].GetSaf().GetForm().Get(0).ToString()) + t.Fatalf( + "Error: %s has not been rewritten as expected. Expected: %s, actual: %s.", + form2.ToString(), + expected.ToString(), + substs[0].GetSaf().GetForm().Get(0).ToString(), + ) } } diff --git a/src/Tests/Equality/equality_test.go b/src/Tests/Equality/equality_test.go index 99b78871..611e54d1 100644 --- a/src/Tests/Equality/equality_test.go +++ b/src/Tests/Equality/equality_test.go @@ -245,59 +245,193 @@ func initTestVariable() { f_a_fbc = basictypes.MakerFun(f_id, basictypes.NewTermList(a, fbc), []typing.TypeApp{}) // Equalities - eq_x_y = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, y), []typing.TypeApp{}) - eq_x_a = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, a), []typing.TypeApp{}) - eq_y_a = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(y, a), []typing.TypeApp{}) - eq_z1_c1 = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(z1, c1), []typing.TypeApp{}) - eq_z1_c2 = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(z1, c2), []typing.TypeApp{}) - eq_z2_c1 = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(z2, c1), []typing.TypeApp{}) - eq_z3_c1 = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(z3, c1), []typing.TypeApp{}) - - eq_ggx_fa = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ggx, fa), []typing.TypeApp{}) - eq_gfy_y = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(gfy, y), []typing.TypeApp{}) - eq_gx_fx = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(gx, fx), []typing.TypeApp{}) - eq_fa_a = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fa, a), []typing.TypeApp{}) - eq_a_b = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, b), []typing.TypeApp{}) - eq_b_c = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(b, c), []typing.TypeApp{}) - eq_a_c = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, c), []typing.TypeApp{}) - eq_b_d = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(b, d), []typing.TypeApp{}) - eq_x_d = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, d), []typing.TypeApp{}) - eq_fx_gab = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fx, gab), []typing.TypeApp{}) - eq_fy_y = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fy, y), []typing.TypeApp{}) - eq_a_ffb = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, ffb), []typing.TypeApp{}) - eq_b_fb = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(b, fb), []typing.TypeApp{}) - eq_fgy_gfy = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fgy, gfy), []typing.TypeApp{}) - eq_fdc_a = basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fdc, a), []typing.TypeApp{}) + eq_x_y = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, y), + []typing.TypeApp{}, + ) + eq_x_a = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, a), + []typing.TypeApp{}, + ) + eq_y_a = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(y, a), + []typing.TypeApp{}, + ) + eq_z1_c1 = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(z1, c1), + []typing.TypeApp{}, + ) + eq_z1_c2 = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(z1, c2), + []typing.TypeApp{}, + ) + eq_z2_c1 = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(z2, c1), + []typing.TypeApp{}, + ) + eq_z3_c1 = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(z3, c1), + []typing.TypeApp{}, + ) + + eq_ggx_fa = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(ggx, fa), + []typing.TypeApp{}, + ) + eq_gfy_y = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(gfy, y), + []typing.TypeApp{}, + ) + eq_gx_fx = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(gx, fx), + []typing.TypeApp{}, + ) + eq_fa_a = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(fa, a), + []typing.TypeApp{}, + ) + eq_a_b = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(a, b), + []typing.TypeApp{}, + ) + eq_b_c = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(b, c), + []typing.TypeApp{}, + ) + eq_a_c = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(a, c), + []typing.TypeApp{}, + ) + eq_b_d = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(b, d), + []typing.TypeApp{}, + ) + eq_x_d = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(x, d), + []typing.TypeApp{}, + ) + eq_fx_gab = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(fx, gab), + []typing.TypeApp{}, + ) + eq_fy_y = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(fy, y), + []typing.TypeApp{}, + ) + eq_a_ffb = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(a, ffb), + []typing.TypeApp{}, + ) + eq_b_fb = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(b, fb), + []typing.TypeApp{}, + ) + eq_fgy_gfy = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(fgy, gfy), + []typing.TypeApp{}, + ) + eq_fdc_a = basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(fdc, a), + []typing.TypeApp{}, + ) // Inequalites - neq_x_a = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, a), []typing.TypeApp{})) - neq_y_a = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(y, a), []typing.TypeApp{})) - neq_a_b = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, b), []typing.TypeApp{})) - neq_a_d = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, d), []typing.TypeApp{})) - neq_gggx_x = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(gggx, x), []typing.TypeApp{})) - neq_fx_a = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fx, a), []typing.TypeApp{})) - neq_fx_x = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fx, x), []typing.TypeApp{})) - neq_fab_fcd = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fab, fcd), []typing.TypeApp{})) - neq_fb_fc = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fb, fc), []typing.TypeApp{})) - neq_hfab_hgxbffb = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(hfab, hgxbffb), []typing.TypeApp{})) - neq_ffb_a = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ffb, a), []typing.TypeApp{})) - neq_x_y = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, y), []typing.TypeApp{})) - neq_ghx_x = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ghx, x), []typing.TypeApp{})) - neq_b_e = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(b, e), []typing.TypeApp{})) - neq_ga_a = basictypes.MakerNot(basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ga, a), []typing.TypeApp{})) + neq_x_a = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, a), []typing.TypeApp{}), + ) + neq_y_a = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(y, a), []typing.TypeApp{}), + ) + neq_a_b = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, b), []typing.TypeApp{}), + ) + neq_a_d = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(a, d), []typing.TypeApp{}), + ) + neq_gggx_x = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(gggx, x), []typing.TypeApp{}), + ) + neq_fx_a = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fx, a), []typing.TypeApp{}), + ) + neq_fx_x = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fx, x), []typing.TypeApp{}), + ) + neq_fab_fcd = basictypes.MakerNot( + basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(fab, fcd), + []typing.TypeApp{}, + ), + ) + neq_fb_fc = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(fb, fc), []typing.TypeApp{}), + ) + neq_hfab_hgxbffb = basictypes.MakerNot( + basictypes.MakerPred( + basictypes.Id_eq, + basictypes.NewTermList(hfab, hgxbffb), + []typing.TypeApp{}, + ), + ) + neq_ffb_a = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ffb, a), []typing.TypeApp{}), + ) + neq_x_y = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(x, y), []typing.TypeApp{}), + ) + neq_ghx_x = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ghx, x), []typing.TypeApp{}), + ) + neq_b_e = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(b, e), []typing.TypeApp{}), + ) + neq_ga_a = basictypes.MakerNot( + basictypes.MakerPred(basictypes.Id_eq, basictypes.NewTermList(ga, a), []typing.TypeApp{}), + ) // Predicates pggab = basictypes.MakerPred(p_id, basictypes.NewTermList(gga, b), []typing.TypeApp{}) - not_pac = basictypes.MakerNot(basictypes.MakerPred(p_id, basictypes.NewTermList(a, c), []typing.TypeApp{})) + not_pac = basictypes.MakerNot( + basictypes.MakerPred(p_id, basictypes.NewTermList(a, c), []typing.TypeApp{}), + ) pa = basictypes.MakerPred(p_id, basictypes.NewTermList(a), []typing.TypeApp{}) pb = basictypes.MakerPred(p_id, basictypes.NewTermList(b), []typing.TypeApp{}) - not_pc = basictypes.RefuteForm(basictypes.MakerPred(p_id, basictypes.NewTermList(c), []typing.TypeApp{})) + not_pc = basictypes.RefuteForm( + basictypes.MakerPred(p_id, basictypes.NewTermList(c), []typing.TypeApp{}), + ) pab = basictypes.MakerPred(p_id, basictypes.NewTermList(a, b), []typing.TypeApp{}) pax = basictypes.MakerPred(p_id, basictypes.NewTermList(a, x), []typing.TypeApp{}) - not_pcd = basictypes.RefuteForm(basictypes.MakerPred(p_id, basictypes.NewTermList(c, d), []typing.TypeApp{})) + not_pcd = basictypes.RefuteForm( + basictypes.MakerPred(p_id, basictypes.NewTermList(c, d), []typing.TypeApp{}), + ) } -func initCodeTreesTests(lf *basictypes.FormList) (datastruct.DataStructure, datastruct.DataStructure) { +func initCodeTreesTests( + lf *basictypes.FormList, +) (datastruct.DataStructure, datastruct.DataStructure) { tp = treesearch.NewNode() tn = treesearch.NewNode() tp = tp.MakeDataStruct(lf, true) @@ -316,7 +450,10 @@ func initEqualityTest() { global.EnableDebug() } -func checkAllCompatibleWith(areCompatbile []treetypes.Substitutions, with ...treetypes.Substitutions) bool { +func checkAllCompatibleWith( + areCompatbile []treetypes.Substitutions, + with ...treetypes.Substitutions, +) bool { for _, isCompatible := range areCompatbile { if !checkSubsIsCompatibleWith(isCompatible, with...) { return false @@ -326,7 +463,10 @@ func checkAllCompatibleWith(areCompatbile []treetypes.Substitutions, with ...tre return true } -func checkSubsIsCompatibleWith(isCompatible treetypes.Substitutions, with ...treetypes.Substitutions) bool { +func checkSubsIsCompatibleWith( + isCompatible treetypes.Substitutions, + with ...treetypes.Substitutions, +) bool { for _, sub := range with { if isFirstIncludedInSecond(sub, isCompatible) { return true @@ -377,7 +517,13 @@ func TestEQ1(t *testing.T) { expectedSubst2.Set(x, gfa) if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2) { - t.Fatalf("Error: %v - %v is not the expected substitution. expected : %v or %v", res, treetypes.SubstListToString(subst), expectedSubst1.ToString(), expectedSubst2.ToString()) + t.Fatalf( + "Error: %v - %v is not the expected substitution. expected : %v or %v", + res, + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + expectedSubst2.ToString(), + ) } } @@ -404,7 +550,13 @@ func TestEQ2(t *testing.T) { expectedSubst2 := treetypes.MakeEmptySubstitution() if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2) { - t.Fatalf("Error: %v - %v is not the expected substitution. expected : %v or %v", res, treetypes.SubstListToString(subst), expectedSubst1.ToString(), expectedSubst2.ToString()) + t.Fatalf( + "Error: %v - %v is not the expected substitution. expected : %v or %v", + res, + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + expectedSubst2.ToString(), + ) } } @@ -436,7 +588,12 @@ func TestEQ3(t *testing.T) { expectedSubst3.Set(y, a) if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2, expectedSubst3) { - t.Fatalf("Error: %v - %v is not the expected substitution. expected : %v", res, treetypes.SubstListToString(subst), expectedSubst1.ToString()) + t.Fatalf( + "Error: %v - %v is not the expected substitution. expected : %v", + res, + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + ) } } @@ -467,7 +624,12 @@ func TestEQ3bis(t *testing.T) { expectedSubst3.Set(y, a) if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2, expectedSubst3) { - t.Fatalf("Error: %v - %v is not the expected substitution. expected : %v", res, treetypes.SubstListToString(subst), expectedSubst1.ToString()) + t.Fatalf( + "Error: %v - %v is not the expected substitution. expected : %v", + res, + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + ) } } @@ -492,7 +654,13 @@ func TestEQ4(t *testing.T) { expectedSubst.Set(x, a) if !res || !checkAllCompatibleWith(subst, expectedSubst) { - t.Fatalf("Error: %v - %v - %v is not the expected substitution. expected : %v", res, len(subst), treetypes.SubstListToString(subst), expectedSubst.ToString()) + t.Fatalf( + "Error: %v - %v - %v is not the expected substitution. expected : %v", + res, + len(subst), + treetypes.SubstListToString(subst), + expectedSubst.ToString(), + ) } } @@ -521,7 +689,13 @@ func TestEQ5(t *testing.T) { expectedSubst2.Set(z2, a) if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2) { - t.Fatalf("Error: %v - %v is not the expected substitution. expected : %v or %v", res, treetypes.SubstListToString(subst), expectedSubst1.ToString(), expectedSubst2.ToString()) + t.Fatalf( + "Error: %v - %v is not the expected substitution. expected : %v or %v", + res, + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + expectedSubst2.ToString(), + ) } } @@ -582,11 +756,29 @@ func TestEQ6(t *testing.T) { expectedSubst3Bis.Set(z3, a) if !res || len(subst) == 0 { - t.Fatalf("Error: %v - %v is not the expected substitution. Expected true and 3", res, len(subst)) + t.Fatalf( + "Error: %v - %v is not the expected substitution. Expected true and 3", + res, + len(subst), + ) } - if !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst1Bis, expectedSubst2, expectedSubst2Bis, expectedSubst3, expectedSubst3Bis) { - t.Fatalf("Error: %v is not the expected substitution. Expected : %v or %v or %v", subst[0].ToString(), expectedSubst1.ToString(), expectedSubst2.ToString(), expectedSubst3.ToString()) + if !checkAllCompatibleWith( + subst, + expectedSubst1, + expectedSubst1Bis, + expectedSubst2, + expectedSubst2Bis, + expectedSubst3, + expectedSubst3Bis, + ) { + t.Fatalf( + "Error: %v is not the expected substitution. Expected : %v or %v or %v", + subst[0].ToString(), + expectedSubst1.ToString(), + expectedSubst2.ToString(), + expectedSubst3.ToString(), + ) } } @@ -606,7 +798,11 @@ func TestEQ7(t *testing.T) { res, subst := equality.EqualityReasoning(eqStruct, tp, tn, lf, 0) if !res || !checkAllCompatibleWith(subst, treetypes.MakeEmptySubstitution()) { - t.Fatalf("Error: %v - %v is not the expected substitution. Expected empty solution", res, treetypes.SubstListToString(subst)) + t.Fatalf( + "Error: %v - %v is not the expected substitution. Expected empty solution", + res, + treetypes.SubstListToString(subst), + ) } } @@ -626,7 +822,11 @@ func TestEQ8(t *testing.T) { res, subst := equality.EqualityReasoning(eqStruct, tp, tn, lf, 0) if res { - t.Fatalf("Error: %v - %v is not the expected solution. Expected no solution", res, treetypes.SubstListToString(subst)) + t.Fatalf( + "Error: %v - %v is not the expected solution. Expected no solution", + res, + treetypes.SubstListToString(subst), + ) } } @@ -647,7 +847,11 @@ func TestImpossible(t *testing.T) { res, subst := equality.EqualityReasoning(eqStruct, tp, tn, lf, 0) if res { - t.Fatalf("Error: %v - %v is not the expected solution. Expected no solution", res, treetypes.SubstListToString(subst)) + t.Fatalf( + "Error: %v - %v is not the expected solution. Expected no solution", + res, + treetypes.SubstListToString(subst), + ) } } @@ -670,7 +874,13 @@ func TestSimon(t *testing.T) { expectedSubst.Set(x, fa) if !res || !checkAllCompatibleWith(subst, expectedSubst) { - t.Fatalf("Error: %v - %v - %v is not the expected substitution. expected : %v", res, len(subst), treetypes.SubstListToString(subst), expectedSubst.ToString()) + t.Fatalf( + "Error: %v - %v - %v is not the expected substitution. expected : %v", + res, + len(subst), + treetypes.SubstListToString(subst), + expectedSubst.ToString(), + ) } } @@ -691,7 +901,11 @@ func TestSeparation(t *testing.T) { res, subst := equality.EqualityReasoning(eqStruct, tp, tn, lf, 0) if !res || !checkAllCompatibleWith(subst, treetypes.MakeEmptySubstitution()) { - t.Fatalf("Error: %v - %v is not the expected substitution. Expected empty solution", res, treetypes.SubstListToString(subst)) + t.Fatalf( + "Error: %v - %v is not the expected substitution. Expected empty solution", + res, + treetypes.SubstListToString(subst), + ) } } @@ -718,7 +932,13 @@ func TestDeuxiemeSeparation(t *testing.T) { expectedSubst2.Set(x, b) if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2) { - t.Fatalf("Error: %v - %v - %v is not the expected substitution. expected : %v", res, len(subst), treetypes.SubstListToString(subst), expectedSubst1.ToString()) + t.Fatalf( + "Error: %v - %v - %v is not the expected substitution. expected : %v", + res, + len(subst), + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + ) } } @@ -747,7 +967,13 @@ func TestMultiListes(t *testing.T) { expectedSubst3 := treetypes.MakeEmptySubstitution() if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2, expectedSubst3) { - t.Fatalf("Error: %v - %v - %v is not the expected substitution. expected : %v", res, len(subst), treetypes.SubstListToString(subst), expectedSubst1.ToString()) + t.Fatalf( + "Error: %v - %v - %v is not the expected substitution. expected : %v", + res, + len(subst), + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + ) } } @@ -774,7 +1000,13 @@ func TestSubsEnMeta(t *testing.T) { expectedSubst3.Set(y, a) if !res || !checkAllCompatibleWith(subst, expectedSubst1, expectedSubst2, expectedSubst3) { - t.Fatalf("Error: %v - %v - %v is not the expected substitution. expected : %v", res, len(subst), treetypes.SubstListToString(subst), expectedSubst1.ToString()) + t.Fatalf( + "Error: %v - %v - %v is not the expected substitution. expected : %v", + res, + len(subst), + treetypes.SubstListToString(subst), + expectedSubst1.ToString(), + ) } } @@ -803,7 +1035,13 @@ func TestContreExemple(t *testing.T) { expectedSubstBis.Set(y, b) if !res || !checkAllCompatibleWith(subst, expectedSubst, expectedSubstBis) { - t.Fatalf("Error: %v - %v - %v is not the expected substitution. expected : %v", res, len(subst), treetypes.SubstListToString(subst), expectedSubst.ToString()) + t.Fatalf( + "Error: %v - %v - %v is not the expected substitution. expected : %v", + res, + len(subst), + treetypes.SubstListToString(subst), + expectedSubst.ToString(), + ) } } @@ -823,7 +1061,11 @@ func TestCycle(t *testing.T) { res, subst := equality.EqualityReasoning(eqStruct, tp, tn, lf, 0) if res { - t.Fatalf("Error: %v - %v is not the expected solution. Expected no solution", res, treetypes.SubstListToString(subst)) + t.Fatalf( + "Error: %v - %v is not the expected solution. Expected no solution", + res, + treetypes.SubstListToString(subst), + ) } } @@ -844,6 +1086,10 @@ func TestTemp(t *testing.T) { res, subst := equality.EqualityReasoning(eqStruct, tp, tn, lf, 0) if res { - t.Fatalf("Error: %v - %v is not the expected solution. Expected no solution", res, treetypes.SubstListToString(subst)) + t.Fatalf( + "Error: %v - %v is not the expected solution. Expected no solution", + res, + treetypes.SubstListToString(subst), + ) } } diff --git a/src/Tests/Typing/polyrules_test.go b/src/Tests/Typing/polyrules_test.go index 67ca72d8..52182c9f 100644 --- a/src/Tests/Typing/polyrules_test.go +++ b/src/Tests/Typing/polyrules_test.go @@ -59,7 +59,10 @@ func TestMain(m *testing.M) { ) typing.SaveTypeScheme( "Q", - typing.MkParameterizedType("map", []typing.TypeApp{typing.MkTypeHint("$int"), typing.MkTypeHint("$int")}), + typing.MkParameterizedType( + "map", + []typing.TypeApp{typing.MkTypeHint("$int"), typing.MkTypeHint("$int")}, + ), typing.DefaultProp(), ) typing.SaveConstant("1", typing.MkTypeHint("$int")) @@ -94,16 +97,22 @@ func TestSimpleDoublePass(t *testing.T) { // Pred should be of type ($int * $int) -> o if !typing.GetOutType(form.GetType()).Equals(typing.DefaultProp()) || !form.GetType().Equals(expected) { - t.Errorf("Formal type verification didn't succeed. Expected: %s, actual: %s", expected.ToString(), form.GetType().ToString()) + t.Errorf( + "Formal type verification didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + form.GetType().ToString(), + ) } } func TestNegDoublePass(t *testing.T) { // ¬P(2, 3) - pred := basictypes.RefuteForm(basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList( - basictypes.MakerConst(basictypes.MakerId("2")), - basictypes.MakerConst(basictypes.MakerId("3")), - ), []typing.TypeApp{})) + pred := basictypes.RefuteForm( + basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList( + basictypes.MakerConst(basictypes.MakerId("2")), + basictypes.MakerConst(basictypes.MakerId("3")), + ), []typing.TypeApp{}), + ) // Double pass pred newPred, err := WellFormedVerification(pred, false) @@ -128,7 +137,11 @@ func TestNegDoublePass(t *testing.T) { ) // Pred should be of type ($int * $int) -> o if !newPred.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), newPred.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + newPred.GetType().ToString(), + ) } } @@ -169,10 +182,18 @@ func TestBinaryDoublePass(t *testing.T) { ) // Pred should be of type ($int * $int) -> o if !F1.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), F1.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + F1.GetType().ToString(), + ) } if !F2.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), F2.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + F2.GetType().ToString(), + ) } // P(2, 2) <=> P(3, 3) @@ -207,10 +228,18 @@ func TestBinaryDoublePass(t *testing.T) { // Pred should be of type ($int * $int) -> o if !F1.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), F1.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + F1.GetType().ToString(), + ) } if !F2.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), F2.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + F2.GetType().ToString(), + ) } } @@ -221,7 +250,11 @@ func TestQuantDoublePass(t *testing.T) { pred := basictypes.MakerAll( []basictypes.Var{x, y}, - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(x, y), []typing.TypeApp{}), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(x, y), + []typing.TypeApp{}, + ), ) // Double pass pred @@ -232,7 +265,10 @@ func TestQuantDoublePass(t *testing.T) { } if _, ok := newPred.(basictypes.All); !ok { - t.Fatalf("Double pass should've returned a forall quantifier. Actual: %s", newPred.ToString()) + t.Fatalf( + "Double pass should've returned a forall quantifier. Actual: %s", + newPred.ToString(), + ) } if !typing.GetOutType(newPred.GetType()).Equals(typing.DefaultProp()) { t.Errorf("Double pass didn't succeed. OutType expected: %s, actual: %s", @@ -247,13 +283,21 @@ func TestQuantDoublePass(t *testing.T) { ) // Pred should be of type ($int * $int) -> o if !newForm.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), newForm.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + newForm.GetType().ToString(), + ) } // exists x y : $int, P(x, y) predEqu := basictypes.MakerEx( []basictypes.Var{x, y}, - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(x, y), []typing.TypeApp{}), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(x, y), + []typing.TypeApp{}, + ), ) // Double pass pred @@ -264,7 +308,10 @@ func TestQuantDoublePass(t *testing.T) { } if _, ok := newPred.(basictypes.Ex); !ok { - t.Fatalf("Double pass should've returned an existential quantifier. Actual: %s", newPred.ToString()) + t.Fatalf( + "Double pass should've returned an existential quantifier. Actual: %s", + newPred.ToString(), + ) } if !typing.GetOutType(newPred.GetType()).Equals(typing.DefaultProp()) { t.Errorf("Double pass didn't succeed. OutType expected: %s, actual: %s", @@ -275,7 +322,11 @@ func TestQuantDoublePass(t *testing.T) { // Pred should be of type ($int * $int) -> o if !newForm.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), newForm.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + newForm.GetType().ToString(), + ) } } @@ -285,10 +336,26 @@ func TestNAryDoublePass(t *testing.T) { three := basictypes.MakerConst(basictypes.MakerId("3")) pred := basictypes.MakerOr(basictypes.NewFormList( - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(two, two), []typing.TypeApp{}), - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(two, three), []typing.TypeApp{}), - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(three, two), []typing.TypeApp{}), - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(three, three), []typing.TypeApp{}), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(two, two), + []typing.TypeApp{}, + ), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(two, three), + []typing.TypeApp{}, + ), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(three, two), + []typing.TypeApp{}, + ), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(three, three), + []typing.TypeApp{}, + ), )) // Double pass pred @@ -299,7 +366,10 @@ func TestNAryDoublePass(t *testing.T) { } if _, ok := newPred.(basictypes.Or); !ok { - t.Fatalf("Double pass should've returned a forall quantifier. Actual: %s", newPred.ToString()) + t.Fatalf( + "Double pass should've returned a forall quantifier. Actual: %s", + newPred.ToString(), + ) } if !typing.GetOutType(newPred.GetType()).Equals(typing.DefaultProp()) { t.Errorf("Double pass didn't succeed. OutType expected: %s, actual: %s", @@ -315,17 +385,37 @@ func TestNAryDoublePass(t *testing.T) { for _, newForm := range newForms.Slice() { // Pred should be of type ($int * $int) -> o if !newForm.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), newForm.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + newForm.GetType().ToString(), + ) } } // P(2, 2) ^ P(2, 3) ^ P(3, 2) ^ P(3, 3) andPred := basictypes.MakerAnd(basictypes.NewFormList( - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(two, two), []typing.TypeApp{}), - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(two, three), []typing.TypeApp{}), - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(three, two), []typing.TypeApp{}), - basictypes.MakerPred(basictypes.MakerId("P"), basictypes.NewTermList(three, three), []typing.TypeApp{}), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(two, two), + []typing.TypeApp{}, + ), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(two, three), + []typing.TypeApp{}, + ), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(three, two), + []typing.TypeApp{}, + ), + basictypes.MakerPred( + basictypes.MakerId("P"), + basictypes.NewTermList(three, three), + []typing.TypeApp{}, + ), )) // Double pass pred @@ -336,7 +426,10 @@ func TestNAryDoublePass(t *testing.T) { } if _, ok := newPred.(basictypes.And); !ok { - t.Fatalf("Double pass should've returned a forall quantifier. Actual: %s", newPred.ToString()) + t.Fatalf( + "Double pass should've returned a forall quantifier. Actual: %s", + newPred.ToString(), + ) } if !typing.GetOutType(newPred.GetType()).Equals(typing.DefaultProp()) { t.Errorf("Double pass didn't succeed. OutType expected: %s, actual: %s", @@ -348,7 +441,11 @@ func TestNAryDoublePass(t *testing.T) { for _, newForm := range newForms.Slice() { // Pred should be of type ($int * $int) -> o if !newForm.GetType().Equals(expected) { - t.Errorf("Double pass didn't succeed. Expected: %s, actual: %s", expected.ToString(), newForm.GetType().ToString()) + t.Errorf( + "Double pass didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + newForm.GetType().ToString(), + ) } } } @@ -397,7 +494,11 @@ func TestBabyNoErr(t *testing.T) { ) if !typing.GetOutType(form.GetType()).Equals(typing.DefaultProp()) || !form.GetType().Equals(expected) { - t.Errorf("Formal type verification didn't succeed. Expected: %s, actual: %s", expected.ToString(), form.GetType().ToString()) + t.Errorf( + "Formal type verification didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + form.GetType().ToString(), + ) } testForm2 := basictypes.MakerEx( @@ -417,7 +518,11 @@ func TestBabyNoErr(t *testing.T) { if !typing.GetOutType(pred.GetType()).Equals(typing.DefaultProp()) || !pred.GetType().Equals(expected) { - t.Errorf("Formal type verification didn't succeed. Expected: %s, actual: %s", expected.ToString(), form.GetType().ToString()) + t.Errorf( + "Formal type verification didn't succeed. Expected: %s, actual: %s", + expected.ToString(), + form.GetType().ToString(), + ) } } @@ -472,7 +577,11 @@ func TestPolymorphicExample(t *testing.T) { pred := form.(basictypes.AllType).GetForm().(basictypes.All).GetForm() if !pred.GetType().Equals(typeScheme) { - t.Fatalf("Type schemes do not match. Expected: %s, actual: %s", typeScheme.ToString(), form.GetType().ToString()) + t.Fatalf( + "Type schemes do not match. Expected: %s, actual: %s", + typeScheme.ToString(), + form.GetType().ToString(), + ) } // GGs! @@ -527,7 +636,17 @@ func TestArithmeticFunction(t *testing.T) { // 1 + 2 <= 3 pred := basictypes.MakerPred( basictypes.MakerId("$lesseq"), - basictypes.NewTermList(basictypes.MakerFun(basictypes.MakerId("$sum"), basictypes.NewTermList(basictypes.MakerConst(basictypes.MakerId("1")), basictypes.MakerConst(basictypes.MakerId("2"))), []typing.TypeApp{}), basictypes.MakerConst(basictypes.MakerId("3"))), + basictypes.NewTermList( + basictypes.MakerFun( + basictypes.MakerId("$sum"), + basictypes.NewTermList( + basictypes.MakerConst(basictypes.MakerId("1")), + basictypes.MakerConst(basictypes.MakerId("2")), + ), + []typing.TypeApp{}, + ), + basictypes.MakerConst(basictypes.MakerId("3")), + ), []typing.TypeApp{}, ) @@ -544,7 +663,14 @@ func TestArithmeticFunction2(t *testing.T) { basictypes.MakerId("$product"), basictypes.NewTermList( basictypes.MakerFun( - basictypes.MakerId("$sum"), basictypes.NewTermList(basictypes.MakerConst(basictypes.MakerId("1")), basictypes.MakerConst(basictypes.MakerId("2"))), []typing.TypeApp{}, + basictypes.MakerId( + "$sum", + ), + basictypes.NewTermList( + basictypes.MakerConst(basictypes.MakerId("1")), + basictypes.MakerConst(basictypes.MakerId("2")), + ), + []typing.TypeApp{}, ), basictypes.MakerConst(basictypes.MakerId("3")), ), @@ -564,13 +690,23 @@ func TestArithmeticFunction2(t *testing.T) { tint := typing.MkTypeHint("$int") expected := typing.MkTypeArrow(typing.MkTypeCross(tint, tint), typing.DefaultProp()) if !typedForm.GetType().Equals(expected) { - t.Fatalf("TypeScheme isn't the expected type. Expected: %s, actual: %s", expected.ToString(), typedForm.GetType().ToString()) + t.Fatalf( + "TypeScheme isn't the expected type. Expected: %s, actual: %s", + expected.ToString(), + typedForm.GetType().ToString(), + ) } termsType := make(map[string]typing.TypeScheme) - termsType[basictypes.MakerId("$product").ToString()] = typing.MkTypeArrow(typing.MkTypeCross(tint, tint), tint) - termsType[basictypes.MakerId("$sum").ToString()] = typing.MkTypeArrow(typing.MkTypeCross(tint, tint), tint) + termsType[basictypes.MakerId("$product").ToString()] = typing.MkTypeArrow( + typing.MkTypeCross(tint, tint), + tint, + ) + termsType[basictypes.MakerId("$sum").ToString()] = typing.MkTypeArrow( + typing.MkTypeCross(tint, tint), + tint, + ) termsType[basictypes.MakerId("1").ToString()] = tint termsType[basictypes.MakerId("2").ToString()] = tint termsType[basictypes.MakerId("3").ToString()] = tint @@ -585,7 +721,12 @@ func checkType(t *testing.T, types map[string]typing.TypeScheme, term basictypes if Is[basictypes.Fun](term) { fun := To[basictypes.Fun](term) if !types[fun.GetID().ToString()].Equals(term.(basictypes.TypedTerm).GetTypeHint()) { - t.Fatalf("Error: wrong TypeScheme for %s. Expected: %s, actual: %s", fun.GetID().ToString(), types[fun.GetID().ToString()].ToString(), term.(basictypes.TypedTerm).GetTypeHint().ToString()) + t.Fatalf( + "Error: wrong TypeScheme for %s. Expected: %s, actual: %s", + fun.GetID().ToString(), + types[fun.GetID().ToString()].ToString(), + term.(basictypes.TypedTerm).GetTypeHint().ToString(), + ) } for _, nt := range fun.GetArgs().Slice() { checkType(t, types, nt) @@ -636,7 +777,14 @@ func TestArithmeticFunction4(t *testing.T) { basictypes.MakerImp( basictypes.MakerPred( basictypes.MakerId("$lesseq"), - basictypes.NewTermList(basictypes.MakerFun(basictypes.MakerId("$sum"), basictypes.NewTermList(x, y), []typing.TypeApp{}), basictypes.MakerConst(basictypes.MakerId("3"))), + basictypes.NewTermList( + basictypes.MakerFun( + basictypes.MakerId("$sum"), + basictypes.NewTermList(x, y), + []typing.TypeApp{}, + ), + basictypes.MakerConst(basictypes.MakerId("3")), + ), []typing.TypeApp{}, ), basictypes.MakerAnd( diff --git a/src/Tests/Typing/z__context_test.go b/src/Tests/Typing/z__context_test.go index 22ee029d..7c7dfeec 100644 --- a/src/Tests/Typing/z__context_test.go +++ b/src/Tests/Typing/z__context_test.go @@ -140,7 +140,12 @@ func TestNormalTS(t *testing.T) { err := SaveTypeScheme(test.name, test.in, test.out) if test.expectedError { if err == nil { - t.Fatalf("Expected error when saving %s : (%s -> %s) but it didn't happen", test.name, test.in.ToString(), test.out.ToString()) + t.Fatalf( + "Expected error when saving %s : (%s -> %s) but it didn't happen", + test.name, + test.in.ToString(), + test.out.ToString(), + ) } } else { if err != nil { @@ -184,7 +189,11 @@ func TestTSConstantSave(t *testing.T) { err := SaveConstant(test.name, test.out) if test.err { if err == nil { - t.Fatalf("Expected error when saving %s : %s but it didn't happen", test.name, test.out.ToString()) + t.Fatalf( + "Expected error when saving %s : %s but it didn't happen", + test.name, + test.out.ToString(), + ) } } else { if err != nil { @@ -245,7 +254,12 @@ func TestTSConstantSaveWithOthersSchemes(t *testing.T) { } testScheme := MkTypeArrow(tInt, test.out) if !scheme.Equals(testScheme) { - t.Fatalf("Wrong type for %s. Expected: %s, actual: %s", test.name, testScheme.ToString(), scheme.ToString()) + t.Fatalf( + "Wrong type for %s. Expected: %s, actual: %s", + test.name, + testScheme.ToString(), + scheme.ToString(), + ) } } }) @@ -268,10 +282,12 @@ func TestFunTypeOrDefault(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) { - if test.defaultExpected && !GetOutType(GetTypeOrDefault(test.name, Fun, test.args)).Equals(DefaultType()) { + if test.defaultExpected && + !GetOutType(GetTypeOrDefault(test.name, Fun, test.args)).Equals(DefaultType()) { t.Fatalf("%s should have default type", test.name) } - if !test.defaultExpected && GetOutType(GetTypeOrDefault(test.name, Fun, test.args)).Equals(DefaultType()) { + if !test.defaultExpected && + GetOutType(GetTypeOrDefault(test.name, Fun, test.args)).Equals(DefaultType()) { t.Fatalf("%s shouldn't have default type", test.name) } }) @@ -299,7 +315,11 @@ func TestPolymorphicSaving(t *testing.T) { err := SavePolymorphScheme(test.name, test.scheme) if test.expectErr { if err == nil { - t.Fatalf("Expected error when saving %s : %s but it didn't happen", test.name, test.scheme.ToString()) + t.Fatalf( + "Expected error when saving %s : %s but it didn't happen", + test.name, + test.scheme.ToString(), + ) } } else { if err != nil { @@ -311,10 +331,18 @@ func TestPolymorphicSaving(t *testing.T) { for i, test := range testTable { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { - scheme := GetPolymorphicType(test.name, test.scheme.QuantifiedVarsLen(), test.scheme.Size()-1) + scheme := GetPolymorphicType( + test.name, + test.scheme.QuantifiedVarsLen(), + test.scheme.Size()-1, + ) if test.saved { if scheme == nil { - t.Fatalf("Couldn't retrieve type scheme %s : %s when it should have been saved", test.name, test.scheme.ToString()) + t.Fatalf( + "Couldn't retrieve type scheme %s : %s when it should have been saved", + test.name, + test.scheme.ToString(), + ) } if !scheme.Equals(test.scheme) { t.Fatalf("Wrong type for polymorphic scheme %s", test.name) diff --git a/src/Tests/Typing/z__paramtype_test.go b/src/Tests/Typing/z__paramtype_test.go index ecdd18fe..08cc3cd8 100644 --- a/src/Tests/Typing/z__paramtype_test.go +++ b/src/Tests/Typing/z__paramtype_test.go @@ -63,15 +63,63 @@ func getTestParamTypeTable() []struct { primitives ComparableList[TypeApp] expectedParameters ComparableList[TypeApp] }{ - {MkParameterizedType("list", []TypeApp{tInt}), "list($int)", []TypeApp{tInt}, []TypeApp{tInt}}, - {MkParameterizedType("list", []TypeApp{tRat}), "list($rat)", []TypeApp{tRat}, []TypeApp{tRat}}, - {MkParameterizedType("map", []TypeApp{tInt, tInt}), "map($int, $int)", []TypeApp{tInt, tInt}, []TypeApp{tInt, tInt}}, - {MkParameterizedType("map", []TypeApp{tInt, tRat}), "map($int, $rat)", []TypeApp{tInt, tRat}, []TypeApp{tInt, tRat}}, - {MkParameterizedType("map", []TypeApp{tRat, tRat}), "map($rat, $rat)", []TypeApp{tRat, tRat}, []TypeApp{tRat, tRat}}, - {MkParameterizedType("pair", []TypeApp{a, tRat}), "pair(a, $rat)", []TypeApp{a, tRat}, []TypeApp{a, tRat}}, - {MkParameterizedType("pair", []TypeApp{MkTypeCross(tInt, tInt), MkTypeCross(tRat, tRat)}), "pair(($int * $int), ($rat * $rat))", []TypeApp{tInt, tInt, tRat, tRat}, []TypeApp{MkTypeCross(tInt, tInt), MkTypeCross(tRat, tRat)}}, - {MkParameterizedType("intMap", []TypeApp{tRat}), "intMap($int, $rat)", []TypeApp{tInt, tRat}, []TypeApp{tInt, tRat}}, - {MkParameterizedType("ratMap", []TypeApp{tInt}), "ratMap($rat, $int)", []TypeApp{tRat, tInt}, []TypeApp{tRat, tInt}}, + { + MkParameterizedType("list", []TypeApp{tInt}), + "list($int)", + []TypeApp{tInt}, + []TypeApp{tInt}, + }, + { + MkParameterizedType("list", []TypeApp{tRat}), + "list($rat)", + []TypeApp{tRat}, + []TypeApp{tRat}, + }, + { + MkParameterizedType("map", []TypeApp{tInt, tInt}), + "map($int, $int)", + []TypeApp{tInt, tInt}, + []TypeApp{tInt, tInt}, + }, + { + MkParameterizedType("map", []TypeApp{tInt, tRat}), + "map($int, $rat)", + []TypeApp{tInt, tRat}, + []TypeApp{tInt, tRat}, + }, + { + MkParameterizedType("map", []TypeApp{tRat, tRat}), + "map($rat, $rat)", + []TypeApp{tRat, tRat}, + []TypeApp{tRat, tRat}, + }, + { + MkParameterizedType("pair", []TypeApp{a, tRat}), + "pair(a, $rat)", + []TypeApp{a, tRat}, + []TypeApp{a, tRat}, + }, + { + MkParameterizedType( + "pair", + []TypeApp{MkTypeCross(tInt, tInt), MkTypeCross(tRat, tRat)}, + ), + "pair(($int * $int), ($rat * $rat))", + []TypeApp{tInt, tInt, tRat, tRat}, + []TypeApp{MkTypeCross(tInt, tInt), MkTypeCross(tRat, tRat)}, + }, + { + MkParameterizedType("intMap", []TypeApp{tRat}), + "intMap($int, $rat)", + []TypeApp{tInt, tRat}, + []TypeApp{tInt, tRat}, + }, + { + MkParameterizedType("ratMap", []TypeApp{tInt}), + "ratMap($rat, $int)", + []TypeApp{tRat, tInt}, + []TypeApp{tRat, tInt}, + }, } } @@ -94,7 +142,11 @@ func TestParamTypeNequal(t *testing.T) { for j, test2 := range tableTest { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if i != j && test.type_.Equals(test2.type_) { - t.Fatalf("Expected %s != %s but it was equal", test.type_.ToString(), test2.type_.ToString()) + t.Fatalf( + "Expected %s != %s but it was equal", + test.type_.ToString(), + test2.type_.ToString(), + ) } }) } @@ -109,7 +161,11 @@ func TestParamTypeNequal2(t *testing.T) { for _, test2 := range tableTest2 { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if test.type_.Equals(test2.type_) { - t.Fatalf("Expected %s != %s but it was equal", test.type_.ToString(), test2.type_.ToString()) + t.Fatalf( + "Expected %s != %s but it was equal", + test.type_.ToString(), + test2.type_.ToString(), + ) } }) } @@ -135,7 +191,11 @@ func TestParamTypeEqual2(t *testing.T) { for j, test2 := range tableTest { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if i == j && !test.type_.Equals(test2.type_) { - t.Fatalf("Expected %s == %s but it was equal", test.type_.ToString(), test2.type_.ToString()) + t.Fatalf( + "Expected %s == %s but it was equal", + test.type_.ToString(), + test2.type_.ToString(), + ) } }) } @@ -148,7 +208,11 @@ func TestParamTypePrimitives(t *testing.T) { for _, test := range tableTest { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if !test.type_.Equals(test.type_.GetPrimitives()[0]) { - t.Fatalf("Expected %s == %s", test.type_.ToString(), test.type_.GetPrimitives()[0].ToString()) + t.Fatalf( + "Expected %s == %s", + test.type_.ToString(), + test.type_.GetPrimitives()[0].ToString(), + ) } }) } diff --git a/src/Tests/Typing/z__quanttype_test.go b/src/Tests/Typing/z__quanttype_test.go index 700ba843..f4f6a3cf 100644 --- a/src/Tests/Typing/z__quanttype_test.go +++ b/src/Tests/Typing/z__quanttype_test.go @@ -62,14 +62,70 @@ func getTestQuantTypeTable() []struct { expectedVars []TypeVar primitives ComparableList[TypeApp] }{ - {MkQuantifiedType([]TypeVar{a}, MkTypeArrow(a, a)), "Π a: Type. (a > a)", []int{0, 1}, 2, []TypeVar{a}, []TypeApp{a, a}}, - {MkQuantifiedType([]TypeVar{b}, MkTypeArrow(b, b)), "Π b: Type. (b > b)", []int{0, 1}, 2, []TypeVar{b}, []TypeApp{b, b}}, - {MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(a, b)), "Π a, b: Type. (a > b)", []int{2}, 2, []TypeVar{a, b}, []TypeApp{a, b}}, - {MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(b, a)), "Π a, b: Type. (b > a)", []int{3}, 2, []TypeVar{a, b}, []TypeApp{b, a}}, - {MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(MkTypeCross(a, b), a)), "Π a, b: Type. ((a * b) > a)", []int{4}, 3, []TypeVar{a, b}, []TypeApp{a, b, a}}, - {MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(MkTypeCross(a, b), b)), "Π a, b: Type. ((a * b) > b)", []int{5}, 3, []TypeVar{a, b}, []TypeApp{a, b, b}}, - {MkQuantifiedType([]TypeVar{a}, MkTypeArrow(MkTypeCross(a, a), a)), "Π a: Type. ((a * a) > a)", []int{6, 7}, 3, []TypeVar{a}, []TypeApp{a, a, a}}, - {MkQuantifiedType([]TypeVar{b}, MkTypeArrow(MkTypeCross(b, b), b)), "Π b: Type. ((b * b) > b)", []int{6, 7}, 3, []TypeVar{b}, []TypeApp{b, b, b}}, + { + MkQuantifiedType([]TypeVar{a}, MkTypeArrow(a, a)), + "Π a: Type. (a > a)", + []int{0, 1}, + 2, + []TypeVar{a}, + []TypeApp{a, a}, + }, + { + MkQuantifiedType([]TypeVar{b}, MkTypeArrow(b, b)), + "Π b: Type. (b > b)", + []int{0, 1}, + 2, + []TypeVar{b}, + []TypeApp{b, b}, + }, + { + MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(a, b)), + "Π a, b: Type. (a > b)", + []int{2}, + 2, + []TypeVar{a, b}, + []TypeApp{a, b}, + }, + { + MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(b, a)), + "Π a, b: Type. (b > a)", + []int{3}, + 2, + []TypeVar{a, b}, + []TypeApp{b, a}, + }, + { + MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(MkTypeCross(a, b), a)), + "Π a, b: Type. ((a * b) > a)", + []int{4}, + 3, + []TypeVar{a, b}, + []TypeApp{a, b, a}, + }, + { + MkQuantifiedType([]TypeVar{a, b}, MkTypeArrow(MkTypeCross(a, b), b)), + "Π a, b: Type. ((a * b) > b)", + []int{5}, + 3, + []TypeVar{a, b}, + []TypeApp{a, b, b}, + }, + { + MkQuantifiedType([]TypeVar{a}, MkTypeArrow(MkTypeCross(a, a), a)), + "Π a: Type. ((a * a) > a)", + []int{6, 7}, + 3, + []TypeVar{a}, + []TypeApp{a, a, a}, + }, + { + MkQuantifiedType([]TypeVar{b}, MkTypeArrow(MkTypeCross(b, b), b)), + "Π b: Type. ((b * b) > b)", + []int{6, 7}, + 3, + []TypeVar{b}, + []TypeApp{b, b, b}, + }, } } @@ -90,11 +146,18 @@ func TestQuantTypeInequality(t *testing.T) { for _, test := range testTable { for j, test2 := range testTable { - t.Run(fmt.Sprintf("%v/%v", test.type_.ToString(), test2.type_.ToString()), func(t *testing.T) { - if !primitiveContains(test.expectedEq, j) && test.type_.Equals(test2.type_) { - t.Fatalf("Expected: %s != %s, but it was equal", test.expectedName, test2.expectedName) - } - }) + t.Run( + fmt.Sprintf("%v/%v", test.type_.ToString(), test2.type_.ToString()), + func(t *testing.T) { + if !primitiveContains(test.expectedEq, j) && test.type_.Equals(test2.type_) { + t.Fatalf( + "Expected: %s != %s, but it was equal", + test.expectedName, + test2.expectedName, + ) + } + }, + ) } } } @@ -104,11 +167,18 @@ func TestQuantTypeEquality(t *testing.T) { for _, test := range testTable { for j, test2 := range testTable { - t.Run(fmt.Sprintf("%v/%v", test.type_.ToString(), test2.type_.ToString()), func(t *testing.T) { - if primitiveContains(test.expectedEq, j) && !test.type_.Equals(test2.type_) { - t.Fatalf("Expected: %s == %s, but it was not equal", test.expectedName, test2.expectedName) - } - }) + t.Run( + fmt.Sprintf("%v/%v", test.type_.ToString(), test2.type_.ToString()), + func(t *testing.T) { + if primitiveContains(test.expectedEq, j) && !test.type_.Equals(test2.type_) { + t.Fatalf( + "Expected: %s == %s, but it was not equal", + test.expectedName, + test2.expectedName, + ) + } + }, + ) } } } @@ -131,7 +201,11 @@ func TestQuantTypeVarsSize(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if test.type_.QuantifiedVarsLen() != len(test.expectedVars) { - t.Fatalf("Expected: %d, actual: %d", len(test.expectedVars), test.type_.QuantifiedVarsLen()) + t.Fatalf( + "Expected: %d, actual: %d", + len(test.expectedVars), + test.type_.QuantifiedVarsLen(), + ) } }) } @@ -143,7 +217,11 @@ func TestQuantTypeVars(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if !test.type_.QuantifiedVars().Equals(test.expectedVars) { - t.Fatalf("Expected: %d, actual: %d", len(test.expectedVars), test.type_.QuantifiedVarsLen()) + t.Fatalf( + "Expected: %d, actual: %d", + len(test.expectedVars), + test.type_.QuantifiedVarsLen(), + ) } }) } @@ -168,9 +246,15 @@ func TestQuantPrimitives2(t *testing.T) { e ComparableList[TypeApp] }{ {MkQuantifiedType([]TypeVar{a}, MkTypeArrow(tInt, a)), []TypeApp{tInt, a}}, - {MkQuantifiedType([]TypeVar{a}, MkTypeArrow(MkTypeCross(tInt, a), a)), []TypeApp{tInt, a, a}}, + { + MkQuantifiedType([]TypeVar{a}, MkTypeArrow(MkTypeCross(tInt, a), a)), + []TypeApp{tInt, a, a}, + }, {MkQuantifiedType([]TypeVar{a}, MkTypeArrow(tInt, a)), []TypeApp{tInt, a}}, - {MkQuantifiedType([]TypeVar{a}, MkTypeArrow(MkTypeCross(tInt, a), MkTypeCross(tInt, a))), []TypeApp{tInt, a, tInt, a}}, + { + MkQuantifiedType([]TypeVar{a}, MkTypeArrow(MkTypeCross(tInt, a), MkTypeCross(tInt, a))), + []TypeApp{tInt, a, tInt, a}, + }, } for _, test := range testTable { diff --git a/src/Tests/Typing/z__tptp_creation_test.go b/src/Tests/Typing/z__tptp_creation_test.go index 066c7f36..637b9836 100644 --- a/src/Tests/Typing/z__tptp_creation_test.go +++ b/src/Tests/Typing/z__tptp_creation_test.go @@ -138,7 +138,11 @@ func TestPrimitive(t *testing.T) { for j, p2 := range primitiveTypes { if i != j { if fst.Equals(p.MkTypeHint(p2)) { - t.Fatalf("Different primitive types (%s, %s) have the same UID !", primitive, p2) + t.Fatalf( + "Different primitive types (%s, %s) have the same UID !", + primitive, + p2, + ) } } } @@ -150,7 +154,10 @@ func TestIsIntFunction(t *testing.T) { t p.TypeHint b bool }{ - {tInt, true}, {tRat, false}, {tReal, false}, {p.MkTypeHint("o"), false}, {p.MkTypeHint("i"), false}, + { + tInt, + true, + }, {tRat, false}, {tReal, false}, {p.MkTypeHint("o"), false}, {p.MkTypeHint("i"), false}, } for _, test := range testTable { @@ -167,7 +174,10 @@ func TestIsRatFunction(t *testing.T) { t p.TypeHint b bool }{ - {tInt, false}, {tRat, true}, {tReal, false}, {p.MkTypeHint("$o"), false}, {p.MkTypeHint("$i"), false}, + { + tInt, + false, + }, {tRat, true}, {tReal, false}, {p.MkTypeHint("$o"), false}, {p.MkTypeHint("$i"), false}, } for _, test := range testTable { @@ -184,7 +194,10 @@ func TestIsRealFunction(t *testing.T) { t p.TypeHint b bool }{ - {tInt, false}, {tRat, false}, {tReal, true}, {p.MkTypeHint("$o"), false}, {p.MkTypeHint("$i"), false}, + { + tInt, + false, + }, {tRat, false}, {tReal, true}, {p.MkTypeHint("$o"), false}, {p.MkTypeHint("$i"), false}, } for _, test := range testTable { @@ -239,7 +252,11 @@ func TestDefaultType3(t *testing.T) { for _, test := range testTable { if p.DefaultFunType(test.size).ToString() != test.name { - t.Fatalf("Wrong default fun type. Expected: %s, actual: %s", test.name, p.DefaultFunType(test.size).ToString()) + t.Fatalf( + "Wrong default fun type. Expected: %s, actual: %s", + test.name, + p.DefaultFunType(test.size).ToString(), + ) } } } @@ -257,7 +274,11 @@ func TestDefaultProp3(t *testing.T) { for _, test := range testTable { if p.DefaultPropType(test.size).ToString() != test.name { - t.Fatalf("Wrong default fun type. Expected: %s, actual: %s", test.name, p.DefaultPropType(test.size).ToString()) + t.Fatalf( + "Wrong default fun type. Expected: %s, actual: %s", + test.name, + p.DefaultPropType(test.size).ToString(), + ) } } } diff --git a/src/Tests/Typing/z__typearrow_test.go b/src/Tests/Typing/z__typearrow_test.go index 3b8fe34a..b53292b5 100644 --- a/src/Tests/Typing/z__typearrow_test.go +++ b/src/Tests/Typing/z__typearrow_test.go @@ -64,15 +64,87 @@ func getTestTypeArrowTable() []struct { expectedInput ComparableList[TypeApp] expectedOutput TypeApp }{ - {MkTypeArrow(tInt, tInt), fmt.Sprintf("(%s -> %s)", intName, intName), 2, []int{0}, []TypeHint{tInt, tInt}, ComparableList[TypeApp]{tInt}, tInt}, - {MkTypeArrow(tInt, tRat), fmt.Sprintf("(%s -> %s)", intName, ratName), 2, []int{1}, []TypeHint{tInt, tRat}, ComparableList[TypeApp]{tInt}, tRat}, - {MkTypeArrow(tRat, tInt), fmt.Sprintf("(%s -> %s)", ratName, intName), 2, []int{2}, []TypeHint{tRat, tInt}, ComparableList[TypeApp]{tRat}, tInt}, - {MkTypeArrow(tRat, tRat), fmt.Sprintf("(%s -> %s)", ratName, ratName), 2, []int{3}, []TypeHint{tRat, tRat}, ComparableList[TypeApp]{tRat}, tRat}, - {MkTypeArrow(tInt, tRat, tInt), fmt.Sprintf("(%s -> %s -> %s)", intName, ratName, intName), 3, []int{4}, []TypeHint{tInt, tRat, tInt}, ComparableList[TypeApp]{tInt, tRat}, tInt}, - {MkTypeArrow(MkTypeCross(tInt, tInt), tRat), fmt.Sprintf("((%s * %s) -> %s)", intName, intName, ratName), 3, []int{5}, []TypeHint{tInt, tInt, tRat}, ComparableList[TypeApp]{MkTypeCross(tInt, tInt)}, tRat}, - {MkTypeArrow(MkTypeCross(tRat, tRat), MkTypeCross(tInt, tInt)), fmt.Sprintf("((%s * %s) -> (%s * %s))", ratName, ratName, intName, intName), 4, []int{6}, []TypeHint{tRat, tRat, tInt, tInt}, ComparableList[TypeApp]{MkTypeCross(tRat, tRat)}, MkTypeCross(tInt, tInt)}, - {MkTypeArrow(MkTypeCross(tRat, tRat, tInt), tInt), fmt.Sprintf("((%s * %s * %s) -> %s)", ratName, ratName, intName, intName), 4, []int{7}, []TypeHint{tRat, tRat, tInt, tInt}, ComparableList[TypeApp]{MkTypeCross(tRat, tRat, tInt)}, tInt}, - {MkTypeArrow(tRat, tRat, tInt, tInt), fmt.Sprintf("(%s -> %s -> %s -> %s)", ratName, ratName, intName, intName), 4, []int{8}, []TypeHint{tRat, tRat, tInt, tInt}, ComparableList[TypeApp]{tRat, tRat, tInt}, tInt}, + { + MkTypeArrow(tInt, tInt), + fmt.Sprintf("(%s -> %s)", intName, intName), + 2, + []int{0}, + []TypeHint{tInt, tInt}, + ComparableList[TypeApp]{tInt}, + tInt, + }, + { + MkTypeArrow(tInt, tRat), + fmt.Sprintf("(%s -> %s)", intName, ratName), + 2, + []int{1}, + []TypeHint{tInt, tRat}, + ComparableList[TypeApp]{tInt}, + tRat, + }, + { + MkTypeArrow(tRat, tInt), + fmt.Sprintf("(%s -> %s)", ratName, intName), + 2, + []int{2}, + []TypeHint{tRat, tInt}, + ComparableList[TypeApp]{tRat}, + tInt, + }, + { + MkTypeArrow(tRat, tRat), + fmt.Sprintf("(%s -> %s)", ratName, ratName), + 2, + []int{3}, + []TypeHint{tRat, tRat}, + ComparableList[TypeApp]{tRat}, + tRat, + }, + { + MkTypeArrow(tInt, tRat, tInt), + fmt.Sprintf("(%s -> %s -> %s)", intName, ratName, intName), + 3, + []int{4}, + []TypeHint{tInt, tRat, tInt}, + ComparableList[TypeApp]{tInt, tRat}, + tInt, + }, + { + MkTypeArrow(MkTypeCross(tInt, tInt), tRat), + fmt.Sprintf("((%s * %s) -> %s)", intName, intName, ratName), + 3, + []int{5}, + []TypeHint{tInt, tInt, tRat}, + ComparableList[TypeApp]{MkTypeCross(tInt, tInt)}, + tRat, + }, + { + MkTypeArrow(MkTypeCross(tRat, tRat), MkTypeCross(tInt, tInt)), + fmt.Sprintf("((%s * %s) -> (%s * %s))", ratName, ratName, intName, intName), + 4, + []int{6}, + []TypeHint{tRat, tRat, tInt, tInt}, + ComparableList[TypeApp]{MkTypeCross(tRat, tRat)}, + MkTypeCross(tInt, tInt), + }, + { + MkTypeArrow(MkTypeCross(tRat, tRat, tInt), tInt), + fmt.Sprintf("((%s * %s * %s) -> %s)", ratName, ratName, intName, intName), + 4, + []int{7}, + []TypeHint{tRat, tRat, tInt, tInt}, + ComparableList[TypeApp]{MkTypeCross(tRat, tRat, tInt)}, + tInt, + }, + { + MkTypeArrow(tRat, tRat, tInt, tInt), + fmt.Sprintf("(%s -> %s -> %s -> %s)", ratName, ratName, intName, intName), + 4, + []int{8}, + []TypeHint{tRat, tRat, tInt, tInt}, + ComparableList[TypeApp]{tRat, tRat, tInt}, + tInt, + }, } } @@ -106,7 +178,11 @@ func TestTypeArrowPrimitives(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if !listEquals(test.expectedPrimitives, test.type_.GetPrimitives()) { - t.Fatalf("Expected: %v, actual: %v", test.expectedPrimitives, test.type_.GetPrimitives()) + t.Fatalf( + "Expected: %v, actual: %v", + test.expectedPrimitives, + test.type_.GetPrimitives(), + ) } }) } @@ -129,11 +205,18 @@ func TestTypeArrowNotEquals(t *testing.T) { for _, test := range testTable { for j, test2 := range testTable { - t.Run(fmt.Sprintf("%v-%v", test.type_.ToString(), test2.type_.ToString()), func(t *testing.T) { - if !primitiveContains(test.expectedEq, j) && test.type_.Equals(test2.type_) { - t.Fatalf("Expected %s != %s, but it was equal", test.type_.ToString(), test2.type_.ToString()) - } - }) + t.Run( + fmt.Sprintf("%v-%v", test.type_.ToString(), test2.type_.ToString()), + func(t *testing.T) { + if !primitiveContains(test.expectedEq, j) && test.type_.Equals(test2.type_) { + t.Fatalf( + "Expected %s != %s, but it was equal", + test.type_.ToString(), + test2.type_.ToString(), + ) + } + }, + ) } } } @@ -150,11 +233,18 @@ func TestTypeArrowNotEquals2(t *testing.T) { for _, test := range testTable { for _, test2 := range testTable2 { - t.Run(fmt.Sprintf("%v-%v", test.type_.ToString(), test2.ToString()), func(t *testing.T) { - if test.type_.Equals(test2) { - t.Fatalf("Expected %s != %s, but it was equal", test.type_.ToString(), test2.ToString()) - } - }) + t.Run( + fmt.Sprintf("%v-%v", test.type_.ToString(), test2.ToString()), + func(t *testing.T) { + if test.type_.Equals(test2) { + t.Fatalf( + "Expected %s != %s, but it was equal", + test.type_.ToString(), + test2.ToString(), + ) + } + }, + ) } } } @@ -198,7 +288,11 @@ func TestRandomInputType(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if GetInputType(test.type_) == nil { - t.Fatalf("Expected: %v, actual: %v", test.type_.ToString(), GetInputType(test.type_)) + t.Fatalf( + "Expected: %v, actual: %v", + test.type_.ToString(), + GetInputType(test.type_), + ) } }) } @@ -210,7 +304,11 @@ func TestRandomOutType(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if !GetOutType(test.type_).Equals(test.type_) { - t.Fatalf("Expected: %s, actual: %s", test.type_.ToString(), GetOutType(test.type_).ToString()) + t.Fatalf( + "Expected: %s, actual: %s", + test.type_.ToString(), + GetOutType(test.type_).ToString(), + ) } }) } diff --git a/src/Tests/Typing/z__typecross_test.go b/src/Tests/Typing/z__typecross_test.go index ca4b4a85..d4083b98 100644 --- a/src/Tests/Typing/z__typecross_test.go +++ b/src/Tests/Typing/z__typecross_test.go @@ -59,15 +59,69 @@ func getTestTypeCrossTable() []struct { expectedEq []int expectedPrimitives []TypeHint }{ - {MkTypeCross(tInt, tInt), fmt.Sprintf("(%s * %s)", intName, intName), 2, []int{0}, []TypeHint{tInt, tInt}}, - {MkTypeCross(tInt, tRat), fmt.Sprintf("(%s * %s)", intName, ratName), 2, []int{1}, []TypeHint{tInt, tRat}}, - {MkTypeCross(tRat, tInt), fmt.Sprintf("(%s * %s)", ratName, intName), 2, []int{2}, []TypeHint{tRat, tInt}}, - {MkTypeCross(tRat, tRat), fmt.Sprintf("(%s * %s)", ratName, ratName), 2, []int{3}, []TypeHint{tRat, tRat}}, - {MkTypeCross(tInt, tRat, tInt), fmt.Sprintf("(%s * %s * %s)", intName, ratName, intName), 3, []int{4}, []TypeHint{tInt, tRat, tInt}}, - {MkTypeCross(MkTypeCross(tInt, tInt), tRat), fmt.Sprintf("((%s * %s) * %s)", intName, intName, ratName), 3, []int{5}, []TypeHint{tInt, tInt, tRat}}, - {MkTypeCross(MkTypeCross(tRat, tRat), MkTypeCross(tInt, tInt)), fmt.Sprintf("((%s * %s) * (%s * %s))", ratName, ratName, intName, intName), 4, []int{6}, []TypeHint{tRat, tRat, tInt, tInt}}, - {MkTypeCross(MkTypeCross(tRat, tRat, tInt), tInt), fmt.Sprintf("((%s * %s * %s) * %s)", ratName, ratName, intName, intName), 4, []int{7}, []TypeHint{tRat, tRat, tInt, tInt}}, - {MkTypeCross(tRat, tRat, tInt, tInt), fmt.Sprintf("(%s * %s * %s * %s)", ratName, ratName, intName, intName), 4, []int{8}, []TypeHint{tRat, tRat, tInt, tInt}}, + { + MkTypeCross(tInt, tInt), + fmt.Sprintf("(%s * %s)", intName, intName), + 2, + []int{0}, + []TypeHint{tInt, tInt}, + }, + { + MkTypeCross(tInt, tRat), + fmt.Sprintf("(%s * %s)", intName, ratName), + 2, + []int{1}, + []TypeHint{tInt, tRat}, + }, + { + MkTypeCross(tRat, tInt), + fmt.Sprintf("(%s * %s)", ratName, intName), + 2, + []int{2}, + []TypeHint{tRat, tInt}, + }, + { + MkTypeCross(tRat, tRat), + fmt.Sprintf("(%s * %s)", ratName, ratName), + 2, + []int{3}, + []TypeHint{tRat, tRat}, + }, + { + MkTypeCross(tInt, tRat, tInt), + fmt.Sprintf("(%s * %s * %s)", intName, ratName, intName), + 3, + []int{4}, + []TypeHint{tInt, tRat, tInt}, + }, + { + MkTypeCross(MkTypeCross(tInt, tInt), tRat), + fmt.Sprintf("((%s * %s) * %s)", intName, intName, ratName), + 3, + []int{5}, + []TypeHint{tInt, tInt, tRat}, + }, + { + MkTypeCross(MkTypeCross(tRat, tRat), MkTypeCross(tInt, tInt)), + fmt.Sprintf("((%s * %s) * (%s * %s))", ratName, ratName, intName, intName), + 4, + []int{6}, + []TypeHint{tRat, tRat, tInt, tInt}, + }, + { + MkTypeCross(MkTypeCross(tRat, tRat, tInt), tInt), + fmt.Sprintf("((%s * %s * %s) * %s)", ratName, ratName, intName, intName), + 4, + []int{7}, + []TypeHint{tRat, tRat, tInt, tInt}, + }, + { + MkTypeCross(tRat, tRat, tInt, tInt), + fmt.Sprintf("(%s * %s * %s * %s)", ratName, ratName, intName, intName), + 4, + []int{8}, + []TypeHint{tRat, tRat, tInt, tInt}, + }, } } @@ -122,7 +176,11 @@ func TestTypeCrossPrimitives(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.type_.ToString()), func(t *testing.T) { if !listEquals(test.expectedPrimitives, test.type_.GetPrimitives()) { - t.Fatalf("Expected: %v, actual: %v", test.expectedPrimitives, test.type_.GetPrimitives()) + t.Fatalf( + "Expected: %v, actual: %v", + test.expectedPrimitives, + test.type_.GetPrimitives(), + ) } }) } @@ -157,11 +215,18 @@ func TestTypeCrossNotEquals(t *testing.T) { for _, test := range testTable { for j, test2 := range testTable { - t.Run(fmt.Sprintf("%v-%v", test.type_.ToString(), test2.type_.ToString()), func(t *testing.T) { - if !primitiveContains(test.expectedEq, j) && test.type_.Equals(test2.type_) { - t.Fatalf("Expected %s != %s, but it was equal", test.type_.ToString(), test2.type_.ToString()) - } - }) + t.Run( + fmt.Sprintf("%v-%v", test.type_.ToString(), test2.type_.ToString()), + func(t *testing.T) { + if !primitiveContains(test.expectedEq, j) && test.type_.Equals(test2.type_) { + t.Fatalf( + "Expected %s != %s, but it was equal", + test.type_.ToString(), + test2.type_.ToString(), + ) + } + }, + ) } } } @@ -172,11 +237,18 @@ func TestTypeCrossNotEquals2(t *testing.T) { for _, test := range testTable { for _, test2 := range testTable2 { - t.Run(fmt.Sprintf("%v-%v", test.type_.ToString(), test2.ToString()), func(t *testing.T) { - if test.type_.Equals(test2) { - t.Fatalf("Expected %s != %s, but it was equal", test.type_.ToString(), test2.ToString()) - } - }) + t.Run( + fmt.Sprintf("%v-%v", test.type_.ToString(), test2.ToString()), + func(t *testing.T) { + if test.type_.Equals(test2) { + t.Fatalf( + "Expected %s != %s, but it was equal", + test.type_.ToString(), + test2.ToString(), + ) + } + }, + ) } } } diff --git a/src/Tests/Typing/z__typehint_test.go b/src/Tests/Typing/z__typehint_test.go index e18091c5..f7581021 100644 --- a/src/Tests/Typing/z__typehint_test.go +++ b/src/Tests/Typing/z__typehint_test.go @@ -89,8 +89,13 @@ func TestTypeHintPrimitives(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.expected), func(t *testing.T) { - if len(test.type_.GetPrimitives()) != 1 || !test.type_.GetPrimitives()[0].(TypeHint).Equals(test.type_) { - t.Fatalf("Expected: %v, actual: %v", []TypeApp{test.type_}, test.type_.GetPrimitives()) + if len(test.type_.GetPrimitives()) != 1 || + !test.type_.GetPrimitives()[0].(TypeHint).Equals(test.type_) { + t.Fatalf( + "Expected: %v, actual: %v", + []TypeApp{test.type_}, + test.type_.GetPrimitives(), + ) } }) } @@ -140,11 +145,14 @@ func TestTypeHintNotEquals2(t *testing.T) { for _, test := range testTable { for _, test2 := range testTable2 { - t.Run(fmt.Sprintf("%v/%v", test.type_.ToString(), test2.type_.ToString()), func(t *testing.T) { - if test.type_.Equals(test2.type_) { - t.Fatalf("Expected that a TypeHint is not a TypeVar") - } - }) + t.Run( + fmt.Sprintf("%v/%v", test.type_.ToString(), test2.type_.ToString()), + func(t *testing.T) { + if test.type_.Equals(test2.type_) { + t.Fatalf("Expected that a TypeHint is not a TypeVar") + } + }, + ) } } } diff --git a/src/Tests/Typing/z__typevar_test.go b/src/Tests/Typing/z__typevar_test.go index 314886d5..f956ef3f 100644 --- a/src/Tests/Typing/z__typevar_test.go +++ b/src/Tests/Typing/z__typevar_test.go @@ -94,8 +94,13 @@ func TestTypeVarPrimitives(t *testing.T) { for _, test := range testTable { t.Run(fmt.Sprintf("%v", test.expected), func(t *testing.T) { - if len(test.type_.GetPrimitives()) != 1 || !test.type_.GetPrimitives()[0].(TypeVar).Equals(test.type_) { - t.Fatalf("Expected: %v, actual: %v", []TypeApp{test.type_}, test.type_.GetPrimitives()) + if len(test.type_.GetPrimitives()) != 1 || + !test.type_.GetPrimitives()[0].(TypeVar).Equals(test.type_) { + t.Fatalf( + "Expected: %v, actual: %v", + []TypeApp{test.type_}, + test.type_.GetPrimitives(), + ) } }) } @@ -216,11 +221,18 @@ func TestTypeVarNotEquals2(t *testing.T) { for _, test := range testTable { for _, test2 := range testTable2 { - t.Run(fmt.Sprintf("%v-%v", test.type_.ToString(), test2.type_.ToString()), func(t *testing.T) { - if test.type_.Equals(test2.type_) { - t.Fatalf("Expected %s != %s, but it was equal", test.type_.ToString(), test2.type_.ToString()) - } - }) + t.Run( + fmt.Sprintf("%v-%v", test.type_.ToString(), test2.type_.ToString()), + func(t *testing.T) { + if test.type_.Equals(test2.type_) { + t.Fatalf( + "Expected %s != %s, but it was equal", + test.type_.ToString(), + test2.type_.ToString(), + ) + } + }, + ) } } } diff --git a/src/Typing/apply_rules.go b/src/Typing/apply_rules.go index 16a7313f..81dd66cf 100644 --- a/src/Typing/apply_rules.go +++ b/src/Typing/apply_rules.go @@ -56,7 +56,9 @@ func applyRule(state Sequent, root *ProofTree, fatherChan chan Reconstruct) Reco if !onlyOneConsequenceIsSet(state) { return Reconstruct{ result: false, - err: fmt.Errorf("multiple elements on the right-side of the sequent. Cannot type this system"), + err: fmt.Errorf( + "multiple elements on the right-side of the sequent. Cannot type this system", + ), } } diff --git a/src/Typing/contexts.go b/src/Typing/contexts.go index ae9faeac..dcafbae8 100644 --- a/src/Typing/contexts.go +++ b/src/Typing/contexts.go @@ -178,7 +178,10 @@ func flattenCross(ty AST.TypeApp) []AST.TypeApp { } /* Search for a TypeScheme with the name & the arguments type */ -func (gc GlobalContext) getSimpleTypeScheme(name string, termsType AST.TypeApp) (AST.TypeScheme, error) { +func (gc GlobalContext) getSimpleTypeScheme( + name string, + termsType AST.TypeApp, +) (AST.TypeScheme, error) { if termsType == nil { if typeScheme, found := gc.simpleSchemes[name]; found { return typeScheme[0], nil @@ -195,11 +198,18 @@ func (gc GlobalContext) getSimpleTypeScheme(name string, termsType AST.TypeApp) } } } - return nil, fmt.Errorf("no predicate/function with the name %s in the global context and arguments of type %s", name, termsType.ToString()) + return nil, fmt.Errorf( + "no predicate/function with the name %s in the global context and arguments of type %s", + name, + termsType.ToString(), + ) } /* Gets the polymorphic type scheme corresponding to the input. */ -func (gc GlobalContext) getPolymorphicTypeScheme(name string, varsLen, termsLen int) (AST.TypeScheme, error) { +func (gc GlobalContext) getPolymorphicTypeScheme( + name string, + varsLen, termsLen int, +) (AST.TypeScheme, error) { if typeSchemeList, found := gc.polymorphSchemes[name]; found { for _, typeScheme := range typeSchemeList { if termsLen == typeScheme.Size()-1 && varsLen == typeScheme.QuantifiedVarsLen() { @@ -312,7 +322,11 @@ func createGlobalContext(context map[string][]AST.App) (GlobalContext, error) { * Triggers rules to verify the global context while it's constructed. * It will avoid combinatorial explosion on global context well formedness verification. **/ -func incrementalVerificationOfGlobalContext(globalContext GlobalContext, name string, app AST.TypeScheme) error { +func incrementalVerificationOfGlobalContext( + globalContext GlobalContext, + name string, + app AST.TypeScheme, +) error { if globalContextIsWellTyped { return nil } diff --git a/src/Typing/form_rules.go b/src/Typing/form_rules.go index c588692f..6672a91d 100644 --- a/src/Typing/form_rules.go +++ b/src/Typing/form_rules.go @@ -207,7 +207,13 @@ func removeOneVar(form AST.Form) (AST.Var, AST.Form) { } /* Makes the child treating the variable depending on which is set. */ -func mkQuantChildren(state Sequent, varInstantiated bool, varTreated AST.Var, typeTreated AST.TypeVar, newForm AST.Form) []Sequent { +func mkQuantChildren( + state Sequent, + varInstantiated bool, + varTreated AST.Var, + typeTreated AST.TypeVar, + newForm AST.Form, +) []Sequent { var type_ AST.TypeApp var newLocalContext LocalContext if varInstantiated { diff --git a/src/Typing/launch_rules.go b/src/Typing/launch_rules.go index 3eb3299b..8c8c9cee 100644 --- a/src/Typing/launch_rules.go +++ b/src/Typing/launch_rules.go @@ -130,7 +130,12 @@ func selectSequents(chansTab [](chan Reconstruct), chanQuit chan Reconstruct) Re } selectCleanup(errorFound, hasAnswered, chansTab) - return Reconstruct{result: errorFound == nil, forms: AST.NewFormList(forms...), terms: terms, err: errorFound} + return Reconstruct{ + result: errorFound == nil, + forms: AST.NewFormList(forms...), + terms: terms, + err: errorFound, + } } /* Utils functions for selectSequents */ @@ -143,7 +148,10 @@ func makeCases(chansTab [](chan Reconstruct), chanQuit chan Reconstruct) []refle cases[i] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(chan_)} } // Father - cases[len(chansTab)] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(chanQuit)} + cases[len(chansTab)] = reflect.SelectCase{ + Dir: reflect.SelectRecv, + Chan: reflect.ValueOf(chanQuit), + } return cases } diff --git a/src/Typing/prooftree_dump.go b/src/Typing/prooftree_dump.go index b2e82f5d..88e9acdf 100644 --- a/src/Typing/prooftree_dump.go +++ b/src/Typing/prooftree_dump.go @@ -134,7 +134,11 @@ func (root *ProofTree) dump() (string, error) { Children: childrenProofs, }) - return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(string(bytes), "\\", ""), "\"{", "{"), "}\"", "}"), err + return strings.ReplaceAll( + strings.ReplaceAll(strings.ReplaceAll(string(bytes), "\\", ""), "\"{", "{"), + "}\"", + "}", + ), err } /* Utils */ diff --git a/src/Typing/term_rules.go b/src/Typing/term_rules.go index 62ae0d6c..e57e7b03 100644 --- a/src/Typing/term_rules.go +++ b/src/Typing/term_rules.go @@ -100,7 +100,10 @@ func applyVarRule(state Sequent, root *ProofTree, fatherChan chan Reconstruct) R if _, ok := getTermFromLocalContext(state.localContext, state.consequence.t); !ok { return Reconstruct{ result: false, - err: fmt.Errorf("term %s not found in the local context", state.consequence.t.ToString()), + err: fmt.Errorf( + "term %s not found in the local context", + state.consequence.t.ToString(), + ), } } diff --git a/src/Typing/type_rules.go b/src/Typing/type_rules.go index 82f03ced..86e34a55 100644 --- a/src/Typing/type_rules.go +++ b/src/Typing/type_rules.go @@ -46,7 +46,11 @@ import ( **/ /* Applies the Var rule for a type variable: erase consequence */ -func applyLocalTypeVarRule(state Sequent, root *ProofTree, fatherChan chan Reconstruct) Reconstruct { +func applyLocalTypeVarRule( + state Sequent, + root *ProofTree, + fatherChan chan Reconstruct, +) Reconstruct { // Add applied rule to the prooftree root.appliedRule = "Var" @@ -54,7 +58,10 @@ func applyLocalTypeVarRule(state Sequent, root *ProofTree, fatherChan chan Recon if _, ok := getTypeFromLocalContext(state.localContext, state.consequence.a.(AST.TypeVar)); !ok { return Reconstruct{ result: false, - err: fmt.Errorf("TypeVar %s not found in the local context", state.consequence.a.ToString()), + err: fmt.Errorf( + "TypeVar %s not found in the local context", + state.consequence.a.ToString(), + ), } } @@ -71,7 +78,11 @@ func applyLocalTypeVarRule(state Sequent, root *ProofTree, fatherChan chan Recon } /* Applies the Var rule for a type hint: erase consequence */ -func applyGlobalTypeVarRule(state Sequent, root *ProofTree, fatherChan chan Reconstruct) Reconstruct { +func applyGlobalTypeVarRule( + state Sequent, + root *ProofTree, + fatherChan chan Reconstruct, +) Reconstruct { // Add applied rule to the prooftree root.appliedRule = "Var" @@ -79,7 +90,10 @@ func applyGlobalTypeVarRule(state Sequent, root *ProofTree, fatherChan chan Reco if found := state.globalContext.isTypeInContext(Glob.To[AST.TypeScheme](state.consequence.a)); !found { return Reconstruct{ result: false, - err: fmt.Errorf("TypeVar %s not found in the global context", state.consequence.a.ToString()), + err: fmt.Errorf( + "TypeVar %s not found in the global context", + state.consequence.a.ToString(), + ), } } @@ -119,7 +133,11 @@ func applyCrossRule(state Sequent, root *ProofTree, fatherChan chan Reconstruct) if tc, ok := state.consequence.a.(AST.TypeCross); ok { // Construct a child for every type recovered - return launchChildren(constructWithTypes(state, tc.GetAllUnderlyingTypes()), root, fatherChan) + return launchChildren( + constructWithTypes(state, tc.GetAllUnderlyingTypes()), + root, + fatherChan, + ) } else { return Reconstruct{ result: false, diff --git a/src/Unif/code-trees.go b/src/Unif/code-trees.go index 0f8687ac..52230e3c 100644 --- a/src/Unif/code-trees.go +++ b/src/Unif/code-trees.go @@ -199,7 +199,9 @@ func (n Node) printAux(tab int) { if n.isLeaf() { for _, form := range n.formulae.Slice() { - debug(Lib.MkLazy(func() string { return strings.Repeat("\t", tab+1) + form.ToString() })) + debug( + Lib.MkLazy(func() string { return strings.Repeat("\t", tab+1) + form.ToString() }), + ) } } debug(Lib.MkLazy(func() string { return "\n" })) @@ -236,7 +238,8 @@ func (n *Node) followInstructions(instructions []Instruction, form AST.Form) { // * It's the end of the CodeBlock, but not of the sequence. In this case, check if the following instruction matches with any child. if instr.IsEquivalent(current.value[oui]) { oui += 1 - if i == len(instructions)-1 && oui == len(current.value) && !current.formulae.Contains(form) { + if i == len(instructions)-1 && oui == len(current.value) && + !current.formulae.Contains(form) { current.formulae.Append(form) } else if i < len(instructions)-1 && oui == len(current.value) { diff --git a/src/Unif/instruction.go b/src/Unif/instruction.go index f8b7e7c0..37a9a13d 100644 --- a/src/Unif/instruction.go +++ b/src/Unif/instruction.go @@ -111,7 +111,9 @@ func (d Down) IsEquivalent(instr Instruction) bool { return reflect.TypeOf(instr) == reflect.TypeOf(d) } func (c Check) IsEquivalent(instr Instruction) bool { - return reflect.TypeOf(instr) == reflect.TypeOf(c) && c.term.GetName() == instr.(Check).term.GetName() && c.term.GetIndex() == instr.(Check).term.GetIndex() + return reflect.TypeOf(instr) == reflect.TypeOf(c) && + c.term.GetName() == instr.(Check).term.GetName() && + c.term.GetIndex() == instr.(Check).term.GetIndex() } func (p Push) IsEquivalent(instr Instruction) bool { return reflect.DeepEqual(p, instr) @@ -123,7 +125,8 @@ func (p Put) IsEquivalent(instr Instruction) bool { return reflect.TypeOf(instr) == reflect.TypeOf(p) && p.i == instr.(Put).i } func (c Compare) IsEquivalent(instr Instruction) bool { - return reflect.TypeOf(instr) == reflect.TypeOf(c) && c.i == instr.(Compare).i && c.j == instr.(Compare).j + return reflect.TypeOf(instr) == reflect.TypeOf(c) && c.i == instr.(Compare).i && + c.j == instr.(Compare).j } /* ToString */ diff --git a/src/Unif/matching.go b/src/Unif/matching.go index ce544e2c..175dd55d 100644 --- a/src/Unif/matching.go +++ b/src/Unif/matching.go @@ -103,8 +103,16 @@ func (m *Machine) unifyAux(node Node) []MatchingSubstitutions { debug(Lib.MkLazy(func() string { return "------------------------" })) debug(Lib.MkLazy(func() string { return fmt.Sprintf("Instr: %v", instr.ToString()) })) debug(Lib.MkLazy(func() string { return fmt.Sprintf("Meta : %v", m.meta.ToString()) })) - debug(Lib.MkLazy(func() string { return fmt.Sprintf("Subst : %v", SubstPairListToString(m.subst)) })) - debug(Lib.MkLazy(func() string { return fmt.Sprintf("Post : %v", IntPairistToString(m.post)) })) + debug( + Lib.MkLazy( + func() string { return fmt.Sprintf("Subst : %v", SubstPairListToString(m.subst)) }, + ), + ) + debug( + Lib.MkLazy( + func() string { return fmt.Sprintf("Post : %v", IntPairistToString(m.post)) }, + ), + ) debug(Lib.MkLazy(func() string { return fmt.Sprintf("IsLocked : %v", m.isLocked()) })) debug(Lib.MkLazy(func() string { return fmt.Sprintf("HasPushed : %v", m.hasPushed) })) debug(Lib.MkLazy(func() string { return fmt.Sprintf("HasPoped : %v", m.hasPoped) })) @@ -128,7 +136,9 @@ func (m *Machine) unifyAux(node Node) []MatchingSubstitutions { Lib.MkLazy(func() string { return fmt.Sprintf("Cursor: %v/%v", m.q, m.terms.Len()) }), ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("m.terms[cursor] : %v", m.terms.At(m.q).ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("m.terms[cursor] : %v", m.terms.At(m.q).ToString()) }, + ), ) debug( Lib.MkLazy(func() string { @@ -174,9 +184,14 @@ func (m *Machine) unifyAux(node Node) []MatchingSubstitutions { if node.isLeaf() { for _, f := range node.formulae.Slice() { - if reflect.TypeOf(f) == reflect.TypeOf(AST.Pred{}) || reflect.TypeOf(f) == reflect.TypeOf(TermForm{}) { + if reflect.TypeOf(f) == reflect.TypeOf(AST.Pred{}) || + reflect.TypeOf(f) == reflect.TypeOf(TermForm{}) { // Rebuild final substitution between meta and subst - final_subst := computeSubstitutions(CopySubstPairList(m.subst), m.meta.Copy(), f.Copy()) + final_subst := computeSubstitutions( + CopySubstPairList(m.subst), + m.meta.Copy(), + f.Copy(), + ) if !final_subst.Equals(Failure()) { matching = append(matching, MakeMatchingSubstitutions(f, final_subst)) } @@ -203,7 +218,9 @@ func (m *Machine) launchChildrenSearch(node Node) []MatchingSubstitutions { channels := []chan []MatchingSubstitutions{} for _, c := range node.children { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Next symbol = %v", c.getValue()[0].ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Next symbol = %v", c.getValue()[0].ToString()) }, + ), ) channels = append(channels, make(chan []MatchingSubstitutions)) } @@ -215,7 +232,19 @@ func (m *Machine) launchChildrenSearch(node Node) []MatchingSubstitutions { ip := CopyIntPairList(m.post) sc := CopySubstPairList(m.subst) - copy := Machine{subst: sc, beginLock: m.beginLock, terms: st, meta: m.meta.Copy(), q: m.q, beginCount: m.beginCount, hasPushed: m.hasPushed, hasPoped: m.hasPoped, post: ip, topLevelTot: m.topLevelTot, topLevelCount: m.topLevelCount} + copy := Machine{ + subst: sc, + beginLock: m.beginLock, + terms: st, + meta: m.meta.Copy(), + q: m.q, + beginCount: m.beginCount, + hasPushed: m.hasPushed, + hasPoped: m.hasPoped, + post: ip, + topLevelTot: m.topLevelTot, + topLevelCount: m.topLevelCount, + } go copy.unifyAuxOnGoroutine(*n, ch, Glob.GetGID()) Glob.IncrGoRoutine(1) diff --git a/src/Unif/parsing.go b/src/Unif/parsing.go index 63393721..1da1bc52 100644 --- a/src/Unif/parsing.go +++ b/src/Unif/parsing.go @@ -48,7 +48,10 @@ func (t TermForm) ToMappedStringSurround(mapping AST.MapString, displayTypes boo return "%s" } -func (t TermForm) ToMappedStringChild(mapping AST.MapString, displayTypes bool) (separator, emptyValue string) { +func (t TermForm) ToMappedStringChild( + mapping AST.MapString, + displayTypes bool, +) (separator, emptyValue string) { return "", t.t.ToMappedString(mapping, displayTypes) } @@ -56,7 +59,8 @@ func (t TermForm) GetChildrenForMappedString() []AST.MappableString { return t.GetChildFormulas().ToMappableStringSlice() } -func (t TermForm) GetTerm() AST.Term { return t.t.Copy() } +func (t TermForm) GetTerm() AST.Term { return t.t.Copy() } + func (t TermForm) Copy() AST.Form { return makeTermForm(t.GetIndex(), t.GetTerm()) } func (t TermForm) GetType() AST.TypeScheme { return AST.DefaultFunType(0) } func (t TermForm) RenameVariables() AST.Form { return t } diff --git a/src/Unif/substitutions_tree.go b/src/Unif/substitutions_tree.go index ab123186..0c8684a2 100644 --- a/src/Unif/substitutions_tree.go +++ b/src/Unif/substitutions_tree.go @@ -49,7 +49,11 @@ import ( * MetaToSubs : (meta, term) : meta in formula, term in tree * Merge both of them **/ -func computeSubstitutions(subs []SubstPair, metasToSubs Substitutions, form AST.Form) Substitutions { +func computeSubstitutions( + subs []SubstPair, + metasToSubs Substitutions, + form AST.Form, +) Substitutions { debug( Lib.MkLazy(func() string { return fmt.Sprintf( @@ -86,7 +90,8 @@ func computeSubstitutions(subs []SubstPair, metasToSubs Substitutions, form AST. if !currentMeta.Equals(currentValue) { // Si current_meta a déjà une association dans metas metaGet, index := metasToSubs.Get(currentMeta) - if HasSubst(metasToSubs, currentMeta) && (index != -1) && !currentValue.Equals(metaGet) { + if HasSubst(metasToSubs, currentMeta) && (index != -1) && + !currentValue.Equals(metaGet) { // On cherche a unifier les deux valeurs treeSubs.Set(currentMeta, currentValue) new_unif := AddUnification(currentValue.Copy(), metaGet.Copy(), treeSubs.Copy()) @@ -103,7 +108,9 @@ func computeSubstitutions(subs []SubstPair, metasToSubs Substitutions, form AST. } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("before meta : %v", metasToSubs.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("before meta : %v", metasToSubs.ToString()) }, + ), ) // Metas_subst eliminate EliminateMeta(&metasToSubs) @@ -111,10 +118,14 @@ func computeSubstitutions(subs []SubstPair, metasToSubs Substitutions, form AST. if metasToSubs.Equals(Failure()) { return Failure() } - debug(Lib.MkLazy(func() string { return fmt.Sprintf("After meta : %v", metasToSubs.ToString()) })) + debug( + Lib.MkLazy(func() string { return fmt.Sprintf("After meta : %v", metasToSubs.ToString()) }), + ) debug( - Lib.MkLazy(func() string { return fmt.Sprintf("before tree_subst : %v", treeSubs.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("before tree_subst : %v", treeSubs.ToString()) }, + ), ) // Tree subst elminate EliminateMeta(&treeSubs) @@ -123,7 +134,9 @@ func computeSubstitutions(subs []SubstPair, metasToSubs Substitutions, form AST. return Failure() } debug( - Lib.MkLazy(func() string { return fmt.Sprintf("after tree_subst : %v", treeSubs.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("after tree_subst : %v", treeSubs.ToString()) }, + ), ) // Fusion @@ -149,7 +162,9 @@ func computeSubstitutions(subs []SubstPair, metasToSubs Substitutions, form AST. /* Call addUnification and returns a status - modify m.meta */ func (m *Machine) trySubstituteMeta(i AST.Term, j AST.Term) Status { debug( - Lib.MkLazy(func() string { return fmt.Sprintf("Try substitute : %v and %v", i.ToString(), j.ToString()) }), + Lib.MkLazy( + func() string { return fmt.Sprintf("Try substitute : %v and %v", i.ToString(), j.ToString()) }, + ), ) new_meta := AddUnification(i, j, m.meta.Copy()) if new_meta.Equals(Failure()) { @@ -210,7 +225,11 @@ func (m *Machine) addUnifications(term1, term2 AST.Term) Status { term2.ToString()) }), ) - meta := tryUnification(term1.Copy(), term2.Copy(), m.meta.Copy()) // Return empty or an array of 1 matching substitution, which is m.meta improved wit (term1, term2) + meta := tryUnification( + term1.Copy(), + term2.Copy(), + m.meta.Copy(), + ) // Return empty or an array of 1 matching substitution, which is m.meta improved wit (term1, term2) if len(meta) == 0 { return Status(ERROR) diff --git a/src/Unif/substitutions_type.go b/src/Unif/substitutions_type.go index 32acc4bc..d68250bd 100644 --- a/src/Unif/substitutions_type.go +++ b/src/Unif/substitutions_type.go @@ -93,7 +93,8 @@ func (s Substitutions) Equals(other any) bool { i := 0 for !found && i < len(typed) { - if subst_s1.Key().Equals(typed[i].Key()) && subst_s1.Value().Equals(typed[i].Value()) { + if subst_s1.Key().Equals(typed[i].Key()) && + subst_s1.Value().Equals(typed[i].Value()) { found = true } @@ -290,7 +291,12 @@ func Eliminate(s *Substitutions) { } /* Eliminate inside : eliminate for a given couple (key, value) on a substitution */ -func eliminateInside(key AST.Meta, value AST.Term, s Substitutions, has_changed_top *bool) Substitutions { +func eliminateInside( + key AST.Meta, + value AST.Term, + s Substitutions, + has_changed_top *bool, +) Substitutions { has_changed := true for has_changed { has_changed = false diff --git a/src/main.go b/src/main.go index 07107474..6595e121 100644 --- a/src/main.go +++ b/src/main.go @@ -126,7 +126,11 @@ func presearchLoader() (AST.Form, int) { Glob.PrintInfo( "preloader", - fmt.Sprintf("You are running problem %s on Goeland v.%s", path.Base(problem), Glob.GetVersion()), + fmt.Sprintf( + "You are running problem %s on Goeland v.%s", + path.Base(problem), + Glob.GetVersion(), + ), ) debug( Lib.MkLazy(func() string { @@ -205,7 +209,11 @@ func initDebuggers() { Unif.InitDebugger() } -func StatementListToFormula(statements []Core.Statement, old_bound int, problemDir string) (form AST.Form, bound int, containsEquality bool) { +func StatementListToFormula( + statements []Core.Statement, + old_bound int, + problemDir string, +) (form AST.Form, bound int, containsEquality bool) { and_list := AST.NewFormList() var not_form AST.Form bound = old_bound @@ -216,7 +224,9 @@ func StatementListToFormula(statements []Core.Statement, old_bound int, problemD file_name := statement.GetName() realname, err := getFile(file_name, problemDir) - debug(Lib.MkLazy(func() string { return fmt.Sprintf("File to parse : %s\n", realname) })) + debug( + Lib.MkLazy(func() string { return fmt.Sprintf("File to parse : %s\n", realname) }), + ) if err != nil { Glob.PrintError(main_label, err.Error()) @@ -308,7 +318,10 @@ func doTypeStatement(atomTyping Core.TFFAtomTyping) { typeScheme := atomTyping.Ts if typeScheme == nil { - Glob.PrintWarn("main", fmt.Sprintf("The constant %s has no type!", atomTyping.Literal.ToString())) + Glob.PrintWarn( + "main", + fmt.Sprintf("The constant %s has no type!", atomTyping.Literal.ToString()), + ) return } diff --git a/src/options.go b/src/options.go index 0fa84bf0..3e1c085a 100644 --- a/src/options.go +++ b/src/options.go @@ -69,7 +69,13 @@ Using this function, you can initialize an option of type T. - funcAlways : a function that will be called regardless if the option was used or not (if it wasn't, the parameter will be 'defaultValue') */ -func (op *option[T]) init(name string, defaultValue T, usage string, funcNotDefault func(T), funcAlways func(T)) { +func (op *option[T]) init( + name string, + defaultValue T, + usage string, + funcNotDefault func(T), + funcAlways func(T), +) { op.initOption(defaultValue, funcNotDefault, funcAlways) switch any(defaultValue).(type) { @@ -96,21 +102,24 @@ func initOpts() { } } -/** +/* +* * An option has a type T and is initialized with five parameters: * name string: the name of the option that will be used in the command line. * defaultValue T: the default value that will be used if the option is not used. * usage string: the description on how to use and what the option does. * funcNotDefault func(T): a function that will be run if the option has changed from its default value. The parameter will be the value of the option. * funcAlways func(T): a function that will always be run. The parameter will be the value of the option. -**/ +* + */ func buildOptions() { (&option[string]{}).init( "debug", "none", "Enables printing debug information in the terminal. Debugging a specific part of the code is possible via -debug a,b,c which will output the debugs of parts a, b and c. If you want all the debugs, use -debug all.", Glob.SetDebug, - func(string) {}) + func(string) {}, + ) (&option[bool]{}).init( "silent", false, @@ -207,7 +216,8 @@ func buildOptions() { false, "Should only be used with the -proof parameter. Enables UTF-8 characters in prints for a pretty proof", func(bool) { Glob.DisplayPretty() }, - func(bool) {}) + func(bool) {}, + ) (&option[bool]{}).init( "dmt", false, @@ -301,7 +311,8 @@ func buildOptions() { false, "Should only be used with the -orocq or the -olp parameters. Enables the context for a standalone execution", func(bool) { rocq.SetContextEnabled(true) }, - func(bool) {}) + func(bool) {}, + ) (&option[bool]{}).init( "inner", false, @@ -319,7 +330,8 @@ func buildOptions() { Core.SetSelectedSkolemization(Sko.MkPreInnerSkolemization()) Glob.SetPreInnerSko(true) }, - func(bool) {}) + func(bool) {}, + ) (&option[bool]{}).init( "assisted", false, @@ -361,7 +373,8 @@ func buildOptions() { func(bool) { chronoInit() }, - func(bool) {}) + func(bool) {}, + ) (&option[bool]{}).init( "incr", false, @@ -377,7 +390,8 @@ func buildOptions() { func(string) {}, func(val string) { Glob.ProofFile = val - }) + }, + ) (&option[bool]{}).init( "vec", false, @@ -388,7 +402,8 @@ func buildOptions() { maxInt := math.MaxInt Glob.SetLimit(maxInt) }, - func(bool) {}) + func(bool) {}, + ) (&option[bool]{}).init( "no_id", false,