public override Element Operateur (Operateurs operateur, Element droite) { if (droite.GetType () != this.GetType ()) { return base.Operateur (operateur, droite); } else if (this.name != ((Inconnue)droite).name) { if (((Inconnue)droite).name == "0") { switch (operateur) { case Operateurs.Addition: return this; case Operateurs.Multiplication: return droite; default: return base.Operateur (operateur, droite); } } else { return base.Operateur (operateur, droite); } } else { switch (operateur) { case Operateurs.Addition: return new Multiplication ((R)2, this); default: return base.Operateur (operateur, droite); } } }
public Element GetValue (Element element) { if(Expression.GetType().IsSubclassOf(typeof(Relation))) { var ExpressionCopy = Expression.Copy (); var l = ((Relation)ExpressionCopy).GetChildsRelations (); foreach(var k in l) { if (k.GetType().IsSubclassOf(typeof(Relation))) { if (((Relation)k).Gauche.GetType () == typeof(Inconnue)) ((Relation)k).Gauche = element; if (((Relation)k).Droite.GetType () == typeof(Inconnue)) ((Relation)k).Droite = element; } } if (ExpressionCopy.GetType ().IsSubclassOf (typeof(Relation))) ExpressionCopy = ((Relation)ExpressionCopy).GetSimple (); return ExpressionCopy; } else { if (Expression.GetType () == typeof(Inconnue)) return element; else return Expression; } }
public override Element Operateur (Operateurs operateur, Element droite) { if (droite.GetType () != this.GetType ()) { return null; } else { switch (operateur) { case Operateurs.Addition: return this + (R) droite; case Operateurs.Multiplication: return this * (R) droite; default: Console.WriteLine ("Operator not handled"); return null; } } }
public Multiplication (Element gauche, Element droite) { Gauche = gauche; Droite = droite; }
public Addition (Element gauche, Element droite) { Gauche = gauche; Droite = droite; }
public virtual Element GetSimple (out bool hasChanged) { hasChanged = false; //Si un neutre if (Gauche == Gauche.Neutre (Name)) { if (Droite.GetType ().IsSubclassOf (typeof(Relation))) return ((Relation)Droite).GetSimple (); else return Droite; } else if (Droite == Droite.Neutre (Name)) { if (Gauche.GetType ().IsSubclassOf (typeof(Relation))) return ((Relation)Gauche).GetSimple (); else return Gauche; } //Développement: on développe d'abord à gauche puis à droite si on ne peut pas if (Droite.GetType ().IsSubclassOf (typeof(Relation))) { if (this.IsDistributiveOn (((Relation)Droite).Name)) { return ((Relation)System.Activator.CreateInstance (Droite.GetType (), (Relation)System.Activator.CreateInstance (this.GetType (), Gauche, ((Relation)Droite).Gauche), (Relation)System.Activator.CreateInstance (this.GetType (), Gauche, ((Relation)Droite).Droite))).GetSimple (); } } if (Droite != Droite.Neutre (this.Name)) { if (Gauche.GetType ().IsSubclassOf (typeof(Relation))) { if (this.IsDistributiveOn (((Relation)Gauche).Name)) { return ((Relation)System.Activator.CreateInstance (Gauche.GetType (), (Relation)System.Activator.CreateInstance (this.GetType (), ((Relation)Gauche).Gauche, Droite), (Relation)System.Activator.CreateInstance (this.GetType (), ((Relation)Gauche).Droite, Droite))).GetSimple (); } } } //Première simplification var continuer = true; while (continuer) { continuer = false; if (Gauche.GetType ().IsSubclassOf (typeof(Relation))) { bool b; Gauche = ((Relation)Gauche).GetSimple (out b); continuer = continuer || b; hasChanged = hasChanged || b; } if (Droite.GetType ().IsSubclassOf (typeof(Relation))) { bool b; Droite = ((Relation)Droite).GetSimple (out b); continuer = continuer || b; hasChanged = hasChanged || b; } } //Associativité && Commutativité if (IsAssociative) { List<Element> liste = new List<Element> (); if (Gauche.GetType () == this.GetType ()) { liste.Add (((Relation)Gauche).Gauche); liste.Add (((Relation)Gauche).Droite); } else { liste.Add (Gauche); } if (Droite.GetType () == this.GetType ()) { liste.Add (((Relation)Droite).Gauche); liste.Add (((Relation)Droite).Droite); } else { liste.Add (Droite); } if (IsCommutative) { for (var i = 0; i < liste.Count; i++) { for (var j = 0; j < liste.Count; j++) { if (i != j && liste [i].GetType () == liste [j].GetType ()) { liste [i] = liste [i].Operateur (this.Name, liste [j]); liste.RemoveAt (j); } } } } else { for (var k = 0; k < liste.Count - 1; k++) { if (liste [k].GetType () == liste [k + 1].GetType ()) { liste [k] = liste [k].Operateur (Name, liste [k + 1]); liste.RemoveAt (k + 1); } } } switch (liste.Count) { case 1: return liste [0]; case 2: Gauche = liste [0]; Droite = liste [1]; break; case 3: Gauche = (Relation)System.Activator.CreateInstance (this.GetType (), liste [0], liste [1]); Gauche = (Relation)System.Activator.CreateInstance (this.GetType (), liste [2], liste [2].Neutre (Name)); break; case 4: Gauche = (Relation)System.Activator.CreateInstance (this.GetType (), liste [0], liste [1]); Gauche = (Relation)System.Activator.CreateInstance (this.GetType (), liste [2], liste [3]); break; } } if (Gauche.GetType () == Droite.GetType ()) { Element tmpValue = this; Element newValue = Gauche.Operateur (Name, Droite); if (newValue != tmpValue) { hasChanged = true; return newValue; } } return this; }
public virtual Element Operateur (Operateurs operateur, Element droite) { return (Element)System.Activator.CreateInstance (Type.GetType ("Maths." + operateur.ToString ()), this, droite); }
public Fonction (Element expression, Inconnue x) { this.Expression = expression; this.x = x; }