/// <summary> /// Метод DecimalToBinary осуществляет перевод чисел с десятиричной в двоичную систему исчесления /// </summary> /// <typeparam name="Type">Входящее десятиричное число</typeparam> /// <returns>Возращает двоичное представление десятиричного числа</returns> public Int32 DecimalToBinary <Type>(Type type) { Type modulo; BinarySystem <Type> binary = new BinarySystem <Type>(); try { while (BooleanFunctions <Type, Int32, Boolean> .Greater(type, 0)) { modulo = ArithmeticFunctionsExcellent <Type, Int32> .ModuloTwo(type, 2); type = ArithmeticFunctionsExcellent <Type, Int32> .DivideTwo(type, 2); binary.Binary.Add(modulo); } } catch (InvalidOperationException e) { Console.WriteLine(e.InnerException); } Int32 Back(List <Type> norm) { Type[] s = new Type[norm.Count()]; for (Int32 i = norm.Count() - 1; i >= 0; i--) { s[norm.Count() - 1 - i] = norm[i]; } return(Convert.ToInt32(String.Join <Type>("", s))); } return(Back(binary.Binary)); }
public override IExpression?Simplify() { var newChild = Child?.Simplify(); if (newChild is ConstantExpression childConst) { // child is constant return(new ConstantExpression(BooleanFunctions.Not(childConst.Value))); } return(new NegateExpression(newChild)); }
private Int32 Count <Type>(Type num, Int32 seed, Int32 modulo) where Type : struct { if (BooleanFunctions <Type, Int32, Boolean> .NotEquals(ArithmeticFunctionsExcellent <Type, Int32> .DivideTwo(num, modulo), 0)) { return(Count(ArithmeticFunctionsExcellent <Type, Int32> .DivideTwo(num, modulo), seed++, modulo)); } else { return(seed); } }
public BooleanExpr(Operator.Op op, Query opnd1, Query opnd2) { Debug.Assert(op == Operator.Op.AND || op == Operator.Op.OR); Debug.Assert(opnd1 != null && opnd2 != null); if (opnd1.StaticType != XPathResultType.Boolean) { opnd1 = new BooleanFunctions(Function.FunctionType.FuncBoolean, opnd1); } if (opnd2.StaticType != XPathResultType.Boolean) { opnd2 = new BooleanFunctions(Function.FunctionType.FuncBoolean, opnd2); } _opnd1 = opnd1; _opnd2 = opnd2; _isOr = (op == Operator.Op.OR); }
/// <summary> /// Метод Sort сортирует коллекцию элементов, за время: /// лучшое: O(n^2), /// в среднем: O(n^2), /// в худшем: O(n^2). /// </summary> /// <typeparam name="T">Строготипизированный параметер метода, указывающий тип элементов коллекции</typeparam> /// <param name="list">Коллекция элементов</param> /// <returns>Возращает отсортированную коллекцию элементов</returns> public static IEnumerable <T> Sort <T>(this IEnumerable <T> list) where T : IComparable <T> { if (!list.Any()) { return(Enumerable.Empty <T>()); } IEnumerable <T> first = list.Where((item, j) => BooleanFunctions <T, T, Boolean> .Equals(list.ElementAt(j + 1), list.ElementAt(j))).Select(y => y).Sort(); IEnumerable <T> a = from item in list let minValue = list.Min() let minIndex = Array.FindIndex(list.ToArray(), x => BooleanFunctions <T, T, Boolean> .Equals(x, minValue)) where BooleanFunctions <T, Int32, Boolean> .Less(list.ToArray()[minIndex + 1], minIndex) orderby item select item; return(first); }
public override IExpression?Simplify() { var newLeft = Left?.Simplify(); var newRight = Right?.Simplify(); var leftConst = newLeft as ConstantExpression; var rightConst = newRight as ConstantExpression; if (leftConst != null && rightConst != null) { // two constants return(new ConstantExpression(BooleanFunctions.Or(leftConst.Value, rightConst.Value))); } if (leftConst?.Value == 1 || rightConst?.Value == 1) { return(new ConstantExpression(1.0)); } return(new OrExpression(newLeft, newRight)); }
private BooleanFunctions(BooleanFunctions other) : base(other) { this.arg = Clone(other.arg); this.funcType = other.funcType; }
protected override Number Evaluate(Number number) { return(BooleanFunctions.Not(number)); }
protected override Number Evaluate(Number number1, Number number2) { return(BooleanFunctions.Or(number1, number2)); }
/// <summary> /// Метод MSort сортирует коллекцию элементов, за время: /// лучшое: O(n*log(n)), /// в среднем: O(n*log(n)), /// в худшем: O(n*log(n)). /// </summary> /// <typeparam name="T">Строготипизированный параметер метода, указывающий тип элементов коллекции</typeparam> /// <param name="list">Коллекция элементов</param> /// <returns>Возращает отсортированную коллекцию элементов</returns> public static IEnumerable <T> Sort <T>(IEnumerable <T> list) where T : IComparable <T> { if (!list.Any()) { return(Enumerable.Empty <T>()); } IEnumerable <T> first = list.Skip(0).Where((item) => list.Count() / 2 + 1 > list .Count() - 1 || (0 <= list.Count() / 2 + 1 && BooleanFunctions <T, T, Boolean> .Less(list.ElementAt(0), list.ElementAt(list.Count() / 2 + 1)))); IEnumerable <T> second = list.Skip(list.Count() / 2 + 1).Where(item => list .Count() / 2 + 1 > list.Count() - 1 || (0 <= list.Count() / 2 + 1 && BooleanFunctions <T, T, Boolean> .Less(list.ElementAt(list.Count() / 2 + 1), list.ElementAt(list.Count() - 1)))); return(first.Concat(second).OrderBy(u => u)); }
/// <summary> /// Перегрузка операции "не равно" /// </summary> /// <param name="left">Левый операнд</param> /// <param name="right">Правый операнд</param> /// <returns>Возращает true или false</returns> public static Boolean operator !=(BinarySystem <Type> left, BinarySystem <Type> right) => BooleanFunctions <Int32, Int32, Boolean> .NotEquals(Hash(left), Hash(right));
private BooleanFunctions(BooleanFunctions other) : base(other) { _arg = Clone(other._arg); _funcType = other._funcType; }
internal AndExpr(Query operand1, Query operand2) { _Operand1 = new BooleanFunctions(operand1); _Operand2 = new BooleanFunctions(operand2); }