コード例 #1
0
        /// <summary>
        /// Updates the light and ambient variables which can then be used to update the shader.
        /// </summary>
        public void UpdateVars()
        {
            switch (type)
            {
            case RenderedObjectType.Terrain:
                TerrainModel terrain = (TerrainModel)modelObject.model;
                light          = ShaderIDTable.ALLOCATED_LIGHTS;
                renderDistance = float.MaxValue;
                break;

            case RenderedObjectType.Moby:
                Moby mob = (Moby)modelObject;
                light          = Math.Max(0, Math.Min(ShaderIDTable.ALLOCATED_LIGHTS, mob.light));
                ambient        = mob.color;
                renderDistance = mob.drawDistance;
                break;

            case RenderedObjectType.Tie:
                Tie tie = (Tie)modelObject;
                light          = Math.Max(0, Math.Min(ShaderIDTable.ALLOCATED_LIGHTS, tie.light));
                renderDistance = float.MaxValue;
                break;

            case RenderedObjectType.Shrub:
                Shrub shrub = (Shrub)modelObject;
                light          = Math.Max(0, Math.Min(ShaderIDTable.ALLOCATED_LIGHTS, shrub.light));
                ambient        = shrub.color;
                renderDistance = shrub.drawDistance;
                break;
            }
        }
コード例 #2
0
    // Call this to set up the display
    public void initialize(Combinator combinator)
    {
        string lambda = combinator.lambdaTerm;

        // From SpawnTarget:createTarget()
        char[] c                  = { '>' };
        var    split              = lambda.Split(c);
        var    tmpStartVariables  = startSMT.Variables;
        var    tmpTargetVariables = targetSMT.Variables;

        // Create Start (proposal)
        // Construct the term using the combinator and then arity variables
        startSMT.Variables = split[0].Skip(1).Where(char.IsLetter).ToList();
        List <Term> termList = new List <Term>();

        termList.Add(Term.Leaf(Sum <Combinator, Variable> .Inl(combinator)));
        for (int i = 0; i < combinator.arity; i++)
        {
            termList.Add(Term.Leaf(Sum <Combinator, Variable> .Inr((Variable)i)));
        }
        startTerm = Term.Node(termList);
        startSMT.CreateTerm(startTerm);
        startSMT.Variables = tmpStartVariables;

        // Create Target
        targetSMT.Variables = split[0].Skip(1).Where(char.IsLetter).ToList();
        goalTerm            = targetSMT.CreateTerm(split[1]);
        targetSMT.Variables = tmpTargetVariables;
    }
コード例 #3
0
        private void Update()
        {
            Console.WriteLine("Enter Name to update: ");
            string name  = Console.ReadLine();
            Shrub  shrub = shrubBusiness.GetShrubByName(name);

            if (shrub != null)
            {
                Console.WriteLine("Enter name: ");
                shrub.Name = Console.ReadLine();
                Console.WriteLine("Enter type: ");
                shrub.Type = Console.ReadLine();
                Console.WriteLine("Enter height: ");
                shrub.Height = decimal.Parse(Console.ReadLine());
                Console.WriteLine("Enter life expectancy: ");
                shrub.LifeExpectancy = Console.ReadLine();
                Console.WriteLine("Enter seasons Id: ");
                Console.WriteLine("(1-spring, 2-summer, 3-autumn, 4-winter)");
                shrub.SeasonsId = int.Parse(Console.ReadLine());
                shrubBusiness.Update(shrub);
                Console.WriteLine("The shrub was updated successfully!");
            }
            else
            {
                Console.WriteLine("Shrub not found!");
            }
        }
コード例 #4
0
    private Term GetTerm()
    {
        var coms = combinators.ToDictionary(c => c.info.nameInfo.name);

        (List <Shrub <char> > input_shrub, var empty) =
            Lambda.Util.ParseParens(input.Where(c => !char.IsWhiteSpace(c)).ToList(), c => c.Equals('('), c => c.Equals(')'));

        if (empty.Count != 0)
        {
            throw new ArgumentException();
        }

        return(Shrub <char> .Node(input_shrub).Map <Sum <Combinator, Lambda.Variable> >(
                   ch =>
        {
            if (coms.ContainsKey(ch))
            {
                return Sum <Combinator, Variable> .Inl(coms[ch]);
            }
            else
            {
                if (Variables.IndexOf(ch) == -1)
                {
                    print($"variable: {ch}, in term: {input_shrub}, vars: {Variables.Select(x => $"{x}").Aggregate((a,b) => $"{a}, {b}")}");
                }
                return Sum <Combinator, Variable> .Inr((Variable)Variables.IndexOf(ch));
            }
        }
                   ));
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        int grass    = Grass.getSeedsOrSaplings(typeof(Grass));
        int shrub    = Shrub.getSeedsOrSaplings(typeof(Shrub));
        int leafTree = LeafTree.getSeedsOrSaplings(typeof(LeafTree));
        int firTree  = Grass.getSeedsOrSaplings(typeof(FirTree));
        int cactus   = Cactus.getSeedsOrSaplings(typeof(Cactus));

        countGrass.text    = grass.ToString();
        countShrub.text    = shrub.ToString();
        countLeafTree.text = leafTree.ToString();
        countFirTree.text  = firTree.ToString();
        countCactus.text   = cactus.ToString();

        if (grass == 0)
        {
            buttonGrass.GetComponent <Button>().interactable = false;
        }
        else
        {
            buttonGrass.GetComponent <Button>().interactable = true;
        }

        if (shrub == 0)
        {
            buttonShrub.GetComponent <Button>().interactable = false;
        }
        else
        {
            buttonShrub.GetComponent <Button>().interactable = true;
        }

        if (leafTree == 0)
        {
            buttonLeafTree.GetComponent <Button>().interactable = false;
        }
        else
        {
            buttonLeafTree.GetComponent <Button>().interactable = true;
        }

        if (firTree == 0)
        {
            buttonFirTree.GetComponent <Button>().interactable = false;
        }
        else
        {
            buttonFirTree.GetComponent <Button>().interactable = true;
        }

        if (cactus == 0)
        {
            buttonCactus.GetComponent <Button>().interactable = false;
        }
        else
        {
            buttonCactus.GetComponent <Button>().interactable = true;
        }
    }
コード例 #6
0
        /// <summary>
        /// Конструктор класса <see cref="Shrub"/>
        /// </summary>
        public static void DefShrub()
        {
            Shrub shrub = new Shrub();

            shrub.Name = "Куст";
            shrub.Size = 50;
            Console.WriteLine($"Куст\nНазвание: {shrub.Name}\nРазмер: {shrub.Size}\n");
        }
コード例 #7
0
    void createTarget(string s)
    {
        char[] c     = { '>' };
        var    split = s.Split(c);
        var    tmp   = smt.Variables;

        smt.Variables = split[0].Skip(1).Where(char.IsLetter).ToList();
        goal          = smt.CreateTerm(split[1]);
        smt.Variables = tmp;
    }
コード例 #8
0
        /// <summary>
        /// Updates shrub.
        /// </summary>
        /// <param name="shrub">the shrub that will be updated</param>
        public void Update(Shrub shrub)
        {
            var item = context.Shrubs.Find(shrub.Id);

            if (item != null)
            {
                context.Entry(item).CurrentValues.SetValues(shrub);
                context.SaveChanges();
            }
        }
コード例 #9
0
        public void Update_Shrub()
        {
            var mockContext   = new Mock <GardenContext>();;
            var shrubBusiness = new ShrubBusiness();
            var Shrub         = new Shrub()
            {
                Name = "Shrub1"
            };

            try { shrubBusiness.Update(Shrub); }
            catch { mockContext.Verify(m => m.Entry(It.IsAny <Shrub>()), Times.Once()); }
        }
コード例 #10
0
        protected List <Shrub> GetShrubs(List <Model> shrubModels, int shrubPointer, int shrubCount)
        {
            List <Shrub> shrubs = new List <Shrub>(shrubCount);

            //Read the whole texture header block, and add models based on the count
            byte[] shrubBlock = ReadBlock(fileStream, shrubPointer, shrubCount * 0x70);
            for (int i = 0; i < shrubCount; i++)
            {
                Shrub shrub = new Shrub(shrubBlock, i, shrubModels);
                shrubs.Add(shrub);
            }
            return(shrubs);
        }
コード例 #11
0
        public void Add_Shrub()
        {
            var mockSet     = new Mock <DbSet <Shrub> >();
            var shrub       = new Shrub();
            var mockContext = new Mock <GardenContext>();

            mockContext.Setup(m => m.Shrubs).Returns(mockSet.Object);

            var business = new ShrubBusiness(mockContext.Object);

            business.Add(shrub);

            mockSet.Verify(m => m.Add(It.IsAny <Shrub>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
コード例 #12
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
        public Shrub <T> evaluate <T>(Shrub <T> term)
        {
            return(term.ApplyAt(t => t.Match(
                                    l => l[0].Match(
                                        leftelement => Shrub <T> .Node(leftelement.Concat(l.Skip(1)).ToList()),
                                        x => throw new Exception() //doesn't begin with parens
                                        ),
                                    x =>
            {
                Debug.Log($" path: {path.Select(i => $"{i}").Aggregate((l,r) => $"{l},{r}")}");
                throw new Exception();
            }
//isn't even an application
                                    ), path));
        }
コード例 #13
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
 public static Shrub <T> FromBinary <T>(BinaryTree <T> tree)
 {
     return(tree.Match <Shrub <T> >((l, r) =>
     {
         var(ll, rr) = (FromBinary <T>(l), FromBinary <T>(r));
         return ll.Match <Shrub <T> >(
             ls => rr.Match(rs => Shrub <T> .Node(ls.Append(Shrub <T> .Node(rs)).ToList()),
                            xr => Shrub <T> .Node(ls.Append(Shrub <T> .Leaf(xr)).ToList())),
             xl =>
             rr.Match(rs => Shrub <T> .Node(rs.Prepend(Shrub <T> .Leaf(xl)).ToList()),
                      xr => Shrub <T> .Node(new List <Shrub <T> > {
             Shrub <T> .Leaf(xl), Shrub <T> .Leaf(xr)
         })
                      ));
     }, Shrub <T> .Leaf));
 }
コード例 #14
0
    Tuple <Shrub <float>, float> findLeftSides(Term term, float leftOffset)
    {
        return(term.Match <Tuple <Shrub <float>, float> >(l =>
        {
            List <Shrub <float> > acc = new List <Shrub <float> >();
            float widths = 0;
            foreach (var shrub in l)
            {
                (var s, float width) = findLeftSides(shrub, leftOffset + widths);
                widths += width;
                acc.Add(s);
            }

            return Tuple.Create(Shrub <float> .Node(acc), widths);
        }, v => Tuple.Create(Shrub <float> .Leaf(leftOffset), lookup_width[v])));
    }
コード例 #15
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
        public static BinaryTree <T> ToBinary <T>(Shrub <T> shrub)
        {
            return(shrub.Match <BinaryTree <T> >(l =>
            {
                int n = l.Count;
                if (n == 0)
                {
                    throw new Exception("Invalid shrub, empty parenthesis");
                }

                if (n == 1)
                {
                    return ToBinary <T>(l[0]);
                }

                return BinaryTree <T> .Node(ToBinary <T>(Shrub <T> .Node(l.Take(n - 1).ToList())), ToBinary <T>(l[n - 1]));
            }, x => BinaryTree <T> .Leaf(x)));
        }
コード例 #16
0
        private void Add()
        {
            Shrub shrub = new Shrub();

            Console.WriteLine("Enter name: ");
            shrub.Name = Console.ReadLine();
            Console.WriteLine("Enter type: ");
            shrub.Type = Console.ReadLine();
            Console.WriteLine("Enter height: ");
            shrub.Height = decimal.Parse(Console.ReadLine());
            Console.WriteLine("Enter life expectancy: ");
            shrub.LifeExpectancy = Console.ReadLine();
            Console.WriteLine("Enter seasons Id: ");
            Console.WriteLine("(1-spring, 2-summer, 3-autumn, 4-winter)");
            shrub.SeasonsId = int.Parse(Console.ReadLine());
            shrubBusiness.Add(shrub);
            Console.WriteLine("The shrub was successfully added!");
        }
コード例 #17
0
    public void Test() //call from button
    {
        var coms = combinators.ToDictionary(c => c.info.nameInfo.name);

        (List <Shrub <char> > input_shrub, var empty) =
            Lambda.Util.ParseParens(inputField.text.ToList(), c => c.Equals('('), c => c.Equals(')'));

        if (empty.Count != 0)
        {
            throw new ArgumentException();
        }



        Term input_term = Shrub <char> .Node(input_shrub).Map <Sum <Combinator, Lambda.Variable> >(
            ch =>
        {
            if (coms.ContainsKey(ch))
            {
                return(Sum <Combinator, Variable> .Inl(coms[ch]));
            }
            else
            {
                return(Sum <Combinator, Variable> .Inr((Variable)variables.IndexOf(ch)));
            }
        }
            );

        List <ElimRule> rules  = Util.CanEvaluate(input_term, new List <int>(), (t, rule) => rule);
        int             cancel = 500;

        print($"Total term: {input_term}");
        while (rules.Count != 0 && input_term.IsNode() && 0 < cancel)
        {
            cancel--;
            Instantiate(text_prefab, outputGroup.transform).text = show(input_term);
            input_term = rules[0].evaluate(input_term);

            print($"Total term: {input_term}");
            rules = Util.CanEvaluate(input_term, new List <int>(), (t, rule) => rule);
        }

        Instantiate(text_prefab, outputGroup.transform).text = show(input_term);
    }
コード例 #18
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
        public Shrub <T> evaluate <T>(Shrub <T> Term)
        {
            (var debuijn, var arity) = Util.ParseCombinator(c)
                                       .Match(
                pi => pi,
                u => throw new Exception(u.ToString())
                );

            return(Term.ApplyAt(
                       t =>
            {
                var args = t.Match(l => l, v => throw new Exception());

                var result = Shrub <T> .Collapse(debuijn.Map(i => i + 1).Map(i => args[i]));

                return result.Match(
                    l => Shrub <T> .Node(l.Concat(args.Skip(arity + 1)).ToList()),
                    u => Shrub <T> .Node(new List <Shrub <T> >().Append(Shrub <T> .Leaf(u)).Concat(args.Skip(arity + 1)).ToList()));
            },
                       path));
        }
コード例 #19
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
        public static Tuple <List <Shrub <T> >, List <T> > ParseParens <T>(List <T> l, Func <T, bool> is_left_paren, Func <T, bool> is_right_paren)
        {
            if (l.Count() != 0)
            {
                if (is_right_paren(l[0]))
                {
                    return(Tuple.Create(new List <Shrub <T> >(), l.Skip(1).ToList()));
                }
                if (is_left_paren(l[0]))
                {
                    (List <Shrub <T> > child, List <T> k)   = ParseParens <T>(l.Skip(1).ToList(), is_left_paren, is_right_paren);
                    (List <Shrub <T> > parent, List <T> kk) = ParseParens <T>(k, is_left_paren, is_right_paren);
                    return(Tuple.Create(parent.Prepend(Shrub <T> .Node(child)).ToList(), kk));
                }

                (List <Shrub <T> > toplevel, List <T> rest) = ParseParens <T>(l.Skip(1).ToList(), is_left_paren, is_right_paren);
                return(Tuple.Create(toplevel.Prepend(Shrub <T> .Leaf(l[0])).ToList(), rest));
            }
            else
            {
                return(Tuple.Create(new List <Shrub <T> >(), l));
            }
        }
コード例 #20
0
    Shrub <GameObject> TransferTerm(Term term, Shrub <GameObject> objs, ElimRule rule)
    //REQUIRES: term and objs share a shape
    {
        var paths_shrub   = NewLocations(term, rule);
        var new_term      = rule.evaluate(term);
        var new_leftsides = findLeftSides(new_term, 0);

        GameObject lookup(Path p)
        {
            GameObject go = null;

            paths_shrub.IterateI(new Path(), (List <List <int> > targets, List <int> source) =>
            {
                if (targets.Exists(target => target.SequenceEqual(p)))
                {
                    //the shapes must match
                    if (targets.FindIndex(target => target.SequenceEqual(p)) == 0)
                    {
                        go = objs.Access(source).Match(l => null, r => r);
                    }
                    else
                    {
                        go = GameObject.Instantiate(objs.Access(source).Match(l => null, r => r));
                    }
                }
            });
            return(go);
        }

        return(new_term.MapI <GameObject>(new Path(), (_, path) =>
        {
            GameObject g = lookup(path);
            StartCoroutine(MoveTo(g, Vector3.right * new_leftsides.Item1.Access(path).Match(l => - 0, r => r)));
            return g;
        }));
    }
コード例 #21
0
        /// <summary>
        /// Проверка метода <c><see cref="Printer.IAmPrinting(Plant)"/></c>
        /// </summary>
        public static void CheckMethod()
        {
            Shrub shrub = new Shrub();

            shrub.Name = "Куст";
            shrub.Size = 50;

            Printer.IAmPrinting(shrub);

            Flower flower = new Flower();

            flower.Name = "Василек";
            flower.Size = 7;

            Printer.IAmPrinting(flower);

            Rose rose = new Rose();

            rose.Name  = "Французская роза";
            rose.Size  = 10.5;
            rose.Color = (Colors)1;

            Printer.IAmPrinting(rose);
        }
コード例 #22
0
 public void HandleClick(SymbolManager manager, Shrub <Sum <Combinator, Variable> > term, List <int> path, LayoutTracker root)
 {
     print("Click happened");
 }
コード例 #23
0
    public IEnumerator _UnTransition(Term newTerm, LayoutTracker lt, Combinator C, List <int> path, LayoutTracker TopSymbol)
    {
        forwardUndoStack.Push(new ForwardData(Sum <ElimRule, AddParenRule> .Inl(new CombinatorElim(C, path)), TopSymbol));

        /*
         * REMEMBER, you've already "typechecked" this operation, you can assume that everything fits
         * Get transform at path
         * Grab transforms at the first occurence of each debruijn index
         * Delete everything else
         * spawn metavariables
         * order everything appropriately
         */

        Transform target = AccessTransfrom(TopSymbol.transform, path);

        (var debruijn, var arity) = Util.ParseCombinator(C)
                                    .Match(
            pi => pi,
            u => throw new Exception(u.ToString())
            );

        debruijn.Match(d =>
        {
            d = d.ToList();
            for (int i = d.Count; i < target.childCount; i++)
            {
                d.Add(Shrub <int> .Leaf(arity));
                arity++;
            }

            debruijn = Shrub <int> .Node(d);
        }, x =>
        {
            var d = new List <Shrub <int> >();
            d.Add(Shrub <int> .Leaf(x));
            for (int i = d.Count; i < target.childCount; i++)
            {
                d.Add(Shrub <int> .Leaf(arity));
                arity++;
            }

            debruijn = Shrub <int> .Node(d);
        });


        Transform[] children = new Transform[arity];
        debruijn.IterateI(new List <int>(), (i, p) =>
        {
            children[i] = AccessTransfrom(target, p, t => t, () => null);
        });

        var canvas = GetComponentInParent <Canvas>();

        foreach (var child in children)
        {
            child?.SetParent(canvas.transform, true);
        }


        foreach (Transform t in target)
        {
            Destroy(t.gameObject);
        }

        lt.LockDown(.1f);
        lt.transform.SetParent(target, true);


        foreach (var child in children)
        {
            if (!child)
            {
                var meta = Instantiate(GetSymbol(Sum <Combinator, Variable> .Inr((Variable)(-1))), target);
                meta.root = skeletonRoot;
            }
            else
            {
                child.SetParent(target, true);
            }
        }

        foreach (Transform t in skeletonRoot)
        {
            Destroy(t.gameObject);
        }
        CreateSkeleton(newTerm, skeletonRoot);
        yield return(new WaitUntil(() =>
        {
            bool moving = false;
            IterateTransform(TopSymbol.transform, t =>
            {
                if (t.GetComponent <LayoutTracker>())
                {
                    moving |= t.GetComponent <LayoutTracker>().Moving();
                }
            });
            return !moving;
        }));
    }
コード例 #24
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
        public static Sum <Term, Unit> BackApply(Term term, Combinator C, List <int> path)
        {
            if (path.Count > 0)
            {
                Debug.Log($"path: {path.Select(i => i.ToString()).Aggregate((a,b) => $"{a}, {b}")}\n term: {show(term)}");
            }
            var target = term.Access(path);

            var(debruijn, arity) = Lambda.Util.ParseCombinator(C).Match(p => p, _ => throw new ArgumentException());


            Sum <Term, Unit> UnifyMeta(Term t1, Term t2)
            {
                return(t1.Match <Sum <Term, Unit> >(l1 => t2.Match <Sum <Term, Unit> >(l2 =>
                {
                    if (l1.Count != l2.Count)
                    {
                        return Sum <Term, Unit> .Inr(new Unit());
                    }
                    List <Term> result = new List <Term>();
                    for (int i = 0; i < l1.Count; i++)
                    {
                        if (UnifyMeta(l1[i], l2[i]).Match(t =>
                        {
                            result.Add(t);
                            return false;
                        }, _ => true))
                        {
                            return Sum <Term, Unit> .Inr(new Unit());
                        }
                    }
                    return Sum <Term, Unit> .Inl(Term.Node(result));
                }
                                                                                       , x2 => x2.Match(c2 => Sum <Term, Unit> .Inr(new Unit()), v2 =>
                {
                    if (((int)v2) == -1)
                    {
                        return Sum <Term, Unit> .Inl(t1);
                    }
                    else
                    {
                        return Sum <Term, Unit> .Inr(new Unit());
                    }
                })
                                                                                       ), x1 => t2.Match <Sum <Term, Unit> >(l2 => x1.Match(c1 => Sum <Term, Unit> .Inr(new Unit()), v1 =>
                {
                    if (((int)v1) == -1)
                    {
                        return Sum <Term, Unit> .Inl(t2);
                    }
                    else
                    {
                        return Sum <Term, Unit> .Inr(new Unit());
                    }
                }), x2 =>
                                                                                                                             x1.Match <Sum <Term, Unit> >(
                                                                                                                                 c1 => x2.Match <Sum <Term, Unit> >(
                                                                                                                                     c2 => c1.Equals(c2) ? Sum <Term, Unit> .Inl(t1) : Sum <Term, Unit> .Inr(new Unit()),
                                                                                                                                     v2 => (int)v2 == -1 ? Sum <Term, Unit> .Inl(t1) : Sum <Term, Unit> .Inr(new Unit()))
                                                                                                                                 , v1 => (int)v1 == -1 ? Sum <Term, Unit> .Inl(t2) :
                                                                                                                                 x2.Match <Sum <Term, Unit> >(
                                                                                                                                     c2 => Sum <Term, Unit> .Inr(new Unit()),
                                                                                                                                     v2 => (int)v2 == -1 ? Sum <Term, Unit> .Inl(t1) :
                                                                                                                                     (v1 == v2 ? Sum <Term, Unit> .Inl(t1) : Sum <Term, Unit> .Inr(new Unit()))))
                                                                                                                             )));
            }

            bool UnifyDebruijn(Shrub <int> d, Term t, Term[] subst)
            {
                //true if unification works
                return(d.Match <bool>(
                           ds => t.Match <bool>(ts =>
                {
                    if (ds.Count != ts.Count)
                    {
                        return false;
                    }
                    for (int i = 0; i < ds.Count; i++)
                    {
                        if (!UnifyDebruijn(ds[i], ts[i], subst))
                        {
                            return false;
                        }
                    }
                    return true;
                }
                                                , xt => { return xt.Match <bool>(c => false, v => (int)v == -1); }), //unification with metavariable unnecessary
                           xd => t.Match <bool>(ts =>
                {
                    return UnifyMeta(subst[xd], t).Match(
                        unified =>
                    {
                        subst[xd] = unified;
                        return true;
                    }, _ => false); //can't apply duplicator
                }, xt =>
                {
                    return xt.Match <bool>(c =>
                                           UnifyMeta(subst[xd], t).Match(
                                               unified =>
                    {
                        subst[xd] = unified;
                        return true;
                    }, _ => false)     //can't apply duplicator
                                           , v =>
                    {
                        if ((int)v == -1)
                        {
                            return true;     //unification unnecessary
                        }
                        else
                        {
                            return UnifyMeta(subst[xd], t).Match(
                                unified =>
                            {
                                subst[xd] = unified;
                                return true;
                            }, _ => false);
                            //unify
                        }
                    }
                                           );
                })));
            }

            //Extend Combinator to fit the whole term
            target.Match(l =>
            {
                debruijn.Match(d =>
                {
                    d = d.ToList();
                    for (int i = d.Count; i < l.Count; i++)
                    {
                        d.Add(Shrub <int> .Leaf(arity));
                        arity++;
                    }

                    debruijn = Shrub <int> .Node(d);
                }, x =>
                {
                    var d = new List <Shrub <int> >();
                    d.Add(Shrub <int> .Leaf(x));
                    for (int i = d.Count; i < l.Count; i++)
                    {
                        d.Add(Shrub <int> .Leaf(arity));
                        arity++;
                    }

                    debruijn = Shrub <int> .Node(d);
                });
            }, _ => {});


            Term[] sub = new Term[arity];
            for (int i = 0; i < arity; i++)
            {
                sub[i] = Term.Leaf(Sum <Combinator, Variable> .Inr((Variable)(-1)));
            }
            if (UnifyDebruijn(debruijn, target, sub))
            {
                return(Sum <Term, Unit> .Inl(term.Update(Term.Node(sub.Prepend(Term.Leaf(Sum <Combinator, Variable> .Inl(C))).ToList()), path)));
            }

            return(Sum <Term, Unit> .Inr(new Unit()));

            //binarify everything TODO don't do this or return a List<Term>
            //unify -- negative variables are metavariables (can be substituted by anything)
            //if unification fails retry with degenerate arity extensions until we hit the left depth of target
            //apply the unification to debruijn adding metavariablese
            // \xyz => (y z) backapplied to ([X]) (where [X] is a metavariable) becomes [Y] [X_1] [X_2]
            // [Y] is created because of the dropped argument and [X_i] gets created as we unify for [X] ~ (y z)
            //unification returns an array of shrubs where each cell holds what needs to be subst in (initialized to new metavariables), and deals with replaces metavariables in the target which might be bad
        }
コード例 #25
0
 /// <summary>
 /// Adds shrub in database.
 /// </summary>
 /// <param name="shrub">the shrub that will be added</param>
 public void Add(Shrub shrub)
 {
     context.Shrubs.Add(shrub);
     context.SaveChanges();
 }
コード例 #26
0
ファイル: Lambda.cs プロジェクト: gantar22/IMPLICITUS
        public static Sum <Tuple <Shrub <int>, int>, Unit> ParseCombinator(Combinator c)
        {
            //Rules for writing combinator definitions
            // 1. Write variables as their debruijn index [x is 0, y is 1, z is 2 ...]
            // 2. There are no lambdas. If you need one, create a new combinator or
            // 3. To self reference, use a capital "Y" [the Y combinator can be written as "0(Y0)"]
            // 4. Use parenthesis to designate order of application as usual
            // 5. It most be non-empty
            // 6. Don't have more than ten variables

            //Examples
            // Bxyz => x(yz) | 0(12)
            // Txy => yx     | 10
            // Cxyz => xzy   | 021
            // Mx => xx      | 00
            // Yx => x(Yx)   | 0(~10)



            string input = c.lambdaTerm;



            if (input == null || input.Equals(""))
            {
                return(Sum <Tuple <Shrub <int>, int>, Unit> .Inr(new Unit()));
            }


            input = String.Concat(input.Where(ch => !char.IsWhiteSpace(ch)));

            char name = input[0];
            Dictionary <char, int> vars = new Dictionary <char, int>();

            int i = 1;

            while (!input[i].Equals('='))
            {
                if (input.Length <= i)
                {
                    Debug.Log($"input length = {input.Length}, i = {i}");
                    return(Sum <Tuple <Shrub <int>, int>, Unit> .Inr(new Unit()));
                }
                else
                {
                    if (vars.ContainsKey(input[i]))
                    {
                        Debug.Log($"non-unique var name {input[i]}");
                        return(Sum <Tuple <Shrub <int>, int>, Unit> .Inr(new Unit()));
                    }
                    vars.Add(input[i], i - 1);
                    i++;
                }
            }
            vars.Add(name, -1); //recursion done with -1


            if (!input[++i].Equals('>'))
            {
                Debug.Log($"Missing \'>\' at index {i}, instead found {input[i]}");
                return(Sum <Tuple <Shrub <int>, int>, Unit> .Inr(new Unit()));
            }

            i++;

            (List <Shrub <char> > shrub, List <char> rest) =
                ParseParens(input.Skip(i).ToList(), ch => ch.Equals('('), ch => ch.Equals(')'));
            if (rest.Count != 0)
            {
                Debug.Log($"Parse parens failed. rest = {String.Concat(rest)}, shrub {Shrub<char>.Node(shrub)}");
                return(Sum <Tuple <Shrub <int>, int>, Unit> .Inr(new Unit()));
            }

            var output = Shrub <char> .Node(shrub).Map <int>(ch => vars[ch]);


            return(Sum <Tuple <Shrub <int>, int>, Unit> .Inl(Tuple.Create <Shrub <int>, int>(output, vars.Count - 1)));
        }
コード例 #27
0
 private void Start()
 {
     smt.GetComponent <SymbolManager>().onCreateTerm.Add(t => goal = t);
 }
コード例 #28
0
 public void addParens(List <int> path, int size, LayoutTracker paren, Shrub <Sum <Combinator, Variable> > newTerm)
 {
     StartCoroutine(smt.GetComponent <SymbolManager>().BackApplyParens(path, size, paren, smt.currentLayout, newTerm));
 }
コード例 #29
0
 public void unApply(Shrub <Sum <Combinator, Variable> > newTerm, LayoutTracker lt, Combinator C, List <int> path)
 {
     StartCoroutine(smt.GetComponent <SymbolManager>().UnTransition(newTerm, lt, C, path, smt.currentLayout));
     goal = newTerm;
     CheckSuccess();
 }
コード例 #30
0
 public void createTarget(Shrub <Sum <Combinator, Variable> > t)
 {
     goal = t;
     smt.CreateTerm(goal);
     CheckSuccess();
 }