New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



IMulti Variable Operation Acceptor in C Sharp


Posted Date:     Total Responses: 0    Posted By: Mahesh   Member Level: Platinum   Points/Cash: 9   


using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace FormulaEditor
{
///
/// Elementary fraction
///

public class ElementaryFraction : IMultiVariableOperationAcceptor, IMultiVariableOperation,
IFormulaCreatorOperation, IDerivationOperation
{

public static readonly ElementaryFraction Object = new ElementaryFraction();

///
/// Return type
///

private const Double a = 0;

private Calculate calc;

///
/// Constructor
///

/// Operation symbol
private ElementaryFraction()
{
calc = standard;
}



///
/// Calculates derivation
///

/// The function for derivation calculation
/// Derivation string
/// The derivation
public ObjectFormulaTree Derivation(ObjectFormulaTree tree, string s)
{
Double a = 0;
bool[] b = new bool[] { false, false };
ObjectFormulaTree[] fc = new ObjectFormulaTree[2];
ObjectFormulaTree[] fd = new ObjectFormulaTree[2];
for (int i = 0; i < 2; i++)
{
fc[i] = tree[1 - i];//.Clone() as ObjectFormulaTree;
fd[i] = DerivationPerformer.Derivation(fc[i], s);
b[i] = ZeroPerformer.IsZero(fd[i]);
}
if (b[0] & b[1])
{
return ElementaryRealConstant.RealZero;
}
IObjectOperation nom = new ElementaryBinaryOperation('-', new object[]{ a, a});
List nomList = new List();
for (int i = 0; i < 2; i++)
{
List l = new List();
l.Add(fd[1 - i]);//.Clone() as ObjectFormulaTree);
l.Add(fc[i]);//.Clone() as ObjectFormulaTree);
IObjectOperation o = new ElementaryBinaryOperation('*', new object[] { a, a});
nomList.Add(new ObjectFormulaTree(o, l));
}
List list = new List();
if (b[0] | b[1])
{
for (int i = 0; i < 2; i++)
{
if (b[i])
{
List lt = new List();
lt.Add(nomList[i]);
list.Add(new ObjectFormulaTree(new ElementaryFunctionOperation('-'), lt));
}
}
}
else
{
list.Add(new ObjectFormulaTree(nom, nomList));
}
IObjectOperation square = ElementaryFunctionsCreator.Object.GetPowerOperation(a, a);
List squareList = new List();
squareList.Add(fc[0]);
squareList.Add(new ObjectFormulaTree(new ElementaryRealConstant(2), new List()));
list.Add(new ObjectFormulaTree(square, squareList));
if (list.Count != 2)
{
list = list;
}
return new ObjectFormulaTree(new ElementaryFraction(), list);
}


///
/// Creates formula
///

/// Operation tree
/// Formula level
/// Sizes of symbols
/// The formula
public MathFormula CreateFormula(ObjectFormulaTree tree, byte level, int[] sizes)
{
MathFormula form = new MathFormula(level, sizes);
MathSymbol sym = new FractionSymbol();
sym.Append(form);
for (int i = 0; i < 2; i++)
{
form.First[i] = FormulaCreator.CreateFormula(tree[i], level, sizes);
}
return form;
}

///
/// Operation priority
///

public int OperationPriority
{
get
{
return (int)ElementaryOperationPriorities.Function;
}
}



///
/// Arity of this operation
///

public int Arity
{
get
{
return 2;
}
}

///
/// Calculates result of this operation
///

public object this[object[] x]
{
get
{
return calc(x);
}
}

///
/// Return type
///

public object ReturnType
{
get
{
return a;
}
}

///
/// The "is powered" sign
///

public bool IsPowered
{
get
{
return false;
}
}



///
/// Accepts operation
///

/// Argument type
/// The operation
public IObjectOperation Accept(object type)
{
if (type.Equals(a))
{
return this;
}
return null;
}

///
/// Accepts operation
///

/// Types of variables
/// Accepted operation
public IObjectOperation Accept(object[] types)
{
if (types.Length < 2)
{
throw new Exception("Incomplete fraction");
}
for (int i = 0; i < types.Length; i++)
{
if (!types[i].Equals(a))
{
ElementaryFraction f = new ElementaryFraction();
Calculate c = f.CreateCalculator(types);
if (c == null)
{
return null;
}
f.calc = c;
return f;
}
}
return this;
}


///
/// Accepts operation
///

/// The symbol
/// Accepted operation
public IMultiVariableOperation AcceptOperation(MathSymbol symbol)
{
if (symbol is FractionSymbol)
{
return this;
}
return null;
}

Calculate CreateCalculator(object[] types)
{
Double a = 0;
Int32 it = 0;
if (types[0].Equals(it) & types[1].Equals(a))
{
return i32_standard;
}
if (types[0].Equals(a) & types[1].Equals(it))
{
return standard_i32;
}
if (types[0].Equals(it) & types[1].Equals(it))
{
return i32_standard_i32;
}
return null;
}


object standard(object[] x)
{
double a = (double)x[0];
double b = (double)x[1];
return a / b;
}

object i32_standard(object[] x)
{
int a = (int)x[0];
double b = (double)x[1];
return (double)a / b;
}

object standard_i32(object[] x)
{
double a = (double)x[0];
int b = (int)x[1];
return a / (double)b;
}

object i32_standard_i32(object[] x)
{
int a = (int)x[0];
int b = (int)x[1];
return (double)a / (double)b;
}


}
}


Project Feedbacks


No feedbacks found. Be the first to respond and make money from revenue sharing program.

Post Feedback
You must Sign In to post a feedback.
Next Project: Dirac delta function of Elementary Function Operation
Previous Project: Elementary root & IMultiVariable Operation Acceptor

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.