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



Elementary Formula Simplification using C Sharp


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


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

namespace FormulaEditor
{
///
/// Summary description for ElementaryFormulaSimplification.
///

public class ElementaryFormulaSimplification : FormulaSimplification
{
//private IFormulaCreatorOperation creator;

private static readonly Double a = 0;

public static readonly ElementaryFormulaSimplification Object = new ElementaryFormulaSimplification();

private ElementaryFormulaSimplification()///*IFormulaCreatorOperation creator)
{
//this.creator = creator;
}

#region IFormulaSimplification Members

public override ObjectFormulaTree Simplify(ObjectFormulaTree tree)
{
ObjectFormulaTree t = tree;//.Clone() as ObjectFormulaTree;
t = simplify(t);
t = PolyMult.MultMult(t);
t = simplify(t);
return PolyMult.MultMultReverse(t);
}




#endregion



private ObjectFormulaTree simplify(ObjectFormulaTree tree)
{
ObjectFormulaTree t = tree;
while (true)
{
bool b;
t = PolyMult.simplify(t, out b);
t = PolySum.Simplify(t, ref b);
if (b)
{
break;
}
}
return t;
}

public static bool IsConst(ObjectFormulaTree tree)
{
for (int i = 0; i < tree.Count; i++)
{
if (!IsConst(tree[i]))
{
return false;
}
}
IObjectOperation op = tree.Operation;
if (op is ElementaryRealConstant)
{
return true;
}
return false;
}

public static object GetValue(ObjectFormulaTree tree)
{
if (!IsConst(tree))
{
return null;
}
return tree.Result;
}

public static ObjectFormulaTree SimplifyContstants(ObjectFormulaTree tree, out bool completed)
{
bool comp = true;
completed = true;
if (IsConst(tree))
{
if (tree.Operation is ElementaryRealConstant)
{
completed = true;
return tree;
}
if (tree.ReturnType.Equals(a))
{
ElementaryRealConstant x = new ElementaryRealConstant((double) tree.Result);
completed = false;
return new ObjectFormulaTree(x, new List());
}
}
List l = new List();
for (int i = 0; i < tree.Count; i++)
{
ObjectFormulaTree t = SimplifyContstants(tree[i], out comp);
if (!comp)
{
completed = false;
}
l.Add(t);
}
return new ObjectFormulaTree(tree.Operation, l);
}
}

}


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: Bitwise operation in C Sharp
Previous Project: Detector of elementary binary operation using C Sharp

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.