Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1094011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:54:44+00:00 2026-05-16T23:54:44+00:00

I am trying to design a way to represent mathematical equations as Java Objects.

  • 0

I am trying to design a way to represent mathematical equations as Java Objects. This is what I’ve come up with so far:

  • Term
  • -Includes fields such as coefficient (which could be negative), exponent and variable (x, y, z, etc). Some fields may even qualify as their own terms alltogether, introducing recursion.
  • -Objects that extend Term would include things such as TrigTerm to represent trigonometric functions.

  • Equation

  • -This is a collection of Terms
  • -The toString() method of Equation would call the toString() method of all of its Terms and concatenate the results.

The overall idea is that I would be able to programmatically manipulate the equations (for example, a dirivative method that would return an equation that is the derivative of the equation it was called for, or an evaluate method that would evaluate an equation for a certain variable equaling a certain value).

What I have works fine for simple equations:
x^2 + 3
This is just two Terms: one with a variable “x” and an exponent “2” and another which is just a constant “3.”

But not so much for more complex equations:
alt text
Yes, this is a terrible example but I’m just making a point.

So now for the question: what would be the best way to represent math equations as Java objects? Are there any libraries that already do this?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:54:45+00:00Added an answer on May 16, 2026 at 11:54 pm

    what would be the best way to
    represent math equations as Java
    objects?

    I want you to notice, you don’t have any equations. Equations look like this;

    x = 3

    What you have are expressions: collections of symbols that could, under some circumstances, evaluate out to some particular values.

    You should write a class Expression. Expression has three subclasses: Constant (e.g. 3), Variable (e.g. x), and Operation.

    An Operation has a type (e.g. “exponentiation” or “negation”) and a list of Expressions to work on. That’s the key idea: an Operation, which is an Expression, also has some number of Expressions.

    So your is SUM(EXP(X, 2), 3) — that is, the SUM Operation, taking two expressions, the first being the Exponentiation of the Expressions Variable X and Constant 2, and the second being the Constant 3.

    This concept can be infinitely elaborated to represent any expression you can write on paper.

    The hard part is evaluating a string that represents your expression and producing an Expression object — as someone suggested, read some papers about parsing. It’s the hardest part but still pretty easy.

    Evaluating an Expression (given fixed values for all your Variables) and printing one out are actually quite easy. More complicated transforms (like differentiation and integration) can be challenging but are still not rocket science.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out the best way to design Car and Road objects
I'm trying to design a lightweight way to store persistent data in Java. I've
I'm trying to find the best way to design my application and precisely my
I am trying to design my Class Diagram. But I get stuck on this
So I've been trying to design a clean way of grabbing data for my
I am trying to design some kind of user to user relationship, such as
I am trying to design a system for something like this with ASP.net/C#. The
I'm trying to do things the DDD (domain driven design) way. And boy do
I'm trying my very best to edit the Magento design the way they want
I'm trying to design a system of chaining constructors in a way that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.