Compute a LaTeX mathematical expression [duplicate] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I need to store a lot of equation and mathematical formula into database for my simulation experimentations, and i think it's better to use some mathML or latex string... but ...
I make some googling request, and i'm very surprised because i don't find any eval library in java or scala to transform string latex or string mathML expression into equation in java / scala. I don't want to eval() very complex equation with solver, my objective is "really" to store and transform simple equation (polynomial, linear) into scala/java language.
Do you have some advice to help me understand if there are other solution to store and parse easily equation or mathematic formula after string evaluation in java or scala language ?
Update 1 :
Finally i find some java library which read et eval() string formula ... If you find anything, i can complete this list with your proposal.
Without parsing of MathML/Latex :
http://www.singularsys.com/jep/ (not open-source)
https://github.com/darius/expr (open-source, young library ?)
http://jeval.sourceforge.net/ (open-source, very old release)
http://projects.congrace.de/exp4j/index.html (open-source, last release 2011, maven repository, developped by #fas)
https://github.com/MarkyVasconcelos/Towel/wiki/Expression (open-source, developped by #marcos-vasconcelos)
math expression parser from my Symja project => cf this post on stackOverflow (Java Math(s) Parsing API)
With experimental Parsing of MathML
jscl-meditor - depository on github Java symbolic computing library and mathematical editor (open-source, last release 2011, great front end and editor, mathML input/output (see tutorial here), great possibilities: polynomial system solving, vectors & matrices, factorization, derivatives, integrals (rational functions), boolean algebra, simplification, java code generation, geometric algebra)
JScience looks like it has some experimental support for MathML being introduced. (cf these post : Parsing mathml document using JScience and MathML and Java)
Class here :
http://jscience.org/experimental/javadoc/org/w3c/dom/mathml/package-tree.html
Thanks

If you want something as sophisticated as I think you are asking for, the only thing that comes to mind that's Java-ecosystem compatible is Clojuratica, and even then you'd have to store the formulae in Mathematica format. (And have a copy of Mathematica.)

Related

Is there any ADA parser written in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am looking to parse ADA code and construct its AST using Java. My belief was that there's a parser written in Java to parse almost every programming language, however after days of research I haven't found anything.
The only promising tool I've found is libadalang (https://github.com/AdaCore/libadalang) by Adacore. However, this only provides api for Ada and Python (although in the readme file Java is mentioned).
Do you have anything to suggest? If there's no direct way of parsing Ada using Java, is any of you familiar with any library that could work as an intermediate? For example, parse Ada using XXX tool and store the AST in a schema (e.g. XML) and then parse the XML using Java?
I'm one of the Libadalang developers, we have indeed planned adding Java bindings at some point, but this is not a high priority item for the moment.
Having a serializer for a common format is something that would be quite easy to add though, especially to the python API were you have full introspection on the tree.
Here is a JSON serializer for the python API of Libadalang:
import json
def node_to_data(self):
if isinstance(self, ASTList):
return [i.to_data() for i in self if i is not None]
else:
return {n: v.to_data()
for n, v in self.iter_fields(with_properties=False)
if v is not None}
def token_to_data(self):
return {"kind": "Token", "token_kind": self.kind, "text": self.text}
ASTNode.to_data = node_to_data
Token.to_data = token_to_data
ASTNode.to_json = lambda self: json.dumps(self.to_data())
I'll add this to the development version of Libadalang soon!
I think I've read that it is possible to call native C libraries from Java.
You could make a C binding to ASIS (Ada Semantic Interface Specification), and then call that from Java.

Why does Java casting have such a strange syntax? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
In Java, when you cast, let’s say, a double to an int, you do this.
int x = (int)(2.5 * 0.4);
In Python, we have this much nicer to read syntax.
x = int(2.5 * 0.4)
Where does this strange form of casting come from? Why is it used?
EDIT:
How is this primarily opinion based? I am looking for factual history on why and where this syntax came from. Please reconsider.
Java's syntax was deliberately and consciously modelled on C (and to a lesser degree) C++ syntax.
Both C and C++ use (<type>) <expr> as the syntax for type casting.
So ...
Where does this strange form of casting come from?
C and C++
Why is it used?
To further the Java design goal of syntactically similarity with C and C++.
This may seem strange to you. However, in the context in which Java was originally designed, the C & C++ languages were dominant. The designers needed to make it easy for C & C++ programmers to transition to Java. If they had ignored this, Java would most likely never have taken off.
Both of those styles have been around for a while: functional and C-like. Given C's prevalence as a code, Java mimicked the style. C++ actually allowed both styles. Python had different goals in choosing its style conventions.
Java was invented at a time when there were a huge number of C programmers in the professional work force, and a slightly smaller number of C++ programmers. The language designers deliberately made the syntax of Java very similar to C and C++, so that this large horde of people would find it easier to learn, and adapt to Java more easily. C-style casting is just one of many syntactic elements in C that Java also uses.

Basic sorting and Searching algorithms for programming (Java) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Where can I learn algorithms for programming(java etc) because when ever I search for programs such as permutations,derangements,sortings etc I always find math algorithms.
Example: Counting Derangement
From this, the following relation is derived:
!n = (n - 1) (!(n-1) + !(n-2)).\,
where !n, known as the subfactorial, represents the number of derangements, with the starting values !0 = 1 and !1 = 0.
Notice that this same recurrence formula also works for factorials with different starting values. That is 0! = 1, 1! = 1 and
n! = (n - 1) ((n-1)! + (n-2)!)\,
which is helpful in proving the limit relationship with e below.
Also, the following formulae are known:[4]
!n = n! \sum_{i=0}^n \frac{(-1)^i}{i!},
!n = \left\lfloor\frac{n!}{e}+\frac{1}{2}\right\rfloor , \quad n\geq 1,
!n = \left[ \frac{n!}{e} \right] , \quad n\geq 1
Also another example I find is when I look up sorting in java I see O(n log n) or O(log n) terminology which I don't understand at all. I am not very good at math but at the same time I am very much interested in programming. Please help me in finding a book or a site to understand sorting algorithms required in programming languages
Algorithms are about mathematics. They are language-agnostic. You can implement algorithms in any language as long as you know its grammar, i.e. its basic datatypes, operators, decision making, etc. Many languages provide libraries implementing known and/or useful algorithms or functionalities (for instance for sorting, encryption, etc.)
That's why searching for "java algorithms" is a bad search string. You should rather search for "java programming basics"
If you want to understand what lies behind (the beauty of) algorithmics, I strongly recommend reading this great book : "Programming Pearls" (2nd edition). The first edition was written in 1983, and it is interesting to understand why the author decided to write a second edition 17 years later.
You can also have a look at online lectures, for instance MIT ones.
Concerning the O(log(n)) part of your question, this is a notation to express the computational complexity of an algorithm (important when you want to understand the performance you can expect from an algorithm, or if you want to communicate the performance of your own algorithms).
For Java you can start with Oracle's tutorials.
I took Algorithms I and Algorithms II on Coursera, they are great. There is also a textbook for that course.
O(n log n) or O(log n) is Big O notation. I linked to the sections where most common cases (like examples you asked for) are explained.
There is also excellent answer on stackoverflow
See Algorithm Tutorials on Topcoder for good articles.
The Importance of Algorithms is good tutorial (explains basic algorithms, and gives examples for Big O notation).
Basics of combinatorics covers your problem -derangements.
For books- see Introduction to Algorithms and Algorithms, 4th Edition.

Is introducing underscores in literals in java beneficial or a drawback? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Though oracle technotes state that :
In Java SE 7 and later, any number of underscore characters (_) can
appear anywhere between digits in a numerical literal. This feature
enables you, for example, to separate groups of digits in numeric
literals, which can improve the readability of your code.
example : float pi = 3.14_15F;
is same as
float pi = 3.1415F;
But does it not become confusing to the developers working on code written by someone else?
Also does the use of underscore put any overhead on compiler or not?
But does it not become confusing to the developers working on code written by someone else?
Only if the developers don't understand the Java language! This construct has been been supported for long enough that every Java professional should recognize it ... even if they don't use it in their own code.
On the other hand, if your Java developers have not bothered to keep up to date with the new things in Java 7, they may be (temporarily) baffled. But the real solution is to educate your developers.
Also does the use of underscore put any overhead on compiler or not?
The overhead would be so small that it is impossible to measure.
There is no performance issue here.
The only time it would make any sense to use underscores is in a very large integer or with a binary integer. Like almost any bit of syntactical freedom the language provides, people are free to misuse it and write difficult to read code. I doubt this underscore thing will become a problem any more than the freedom to add extra white space is a problem.
The best example for when you would want to use this is with binary numbers where it is customary to place a space between every 4 bits.
For instance, compare:
int bitField = 0b110111011111;
int bitField2= 0b1101_1101_1111; //clearly more readable.
Other examples might include a credit card number or SSN as given in Oracle's documentation of this feature.

Unable to parse this kind of string to java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have this string of values and don't understand how to get the object array name and values of object items in java.
{
"employees": [
{ "firstName":"Rajesh" , "lastName":"Putta" },
{ "firstName":"Rajesh" , "lastName":"P" },
{ "firstName":"first name" , "lastName":"last name" }
]
}
This is basically a json stirng. Check more about it here:
JSON (JavaScript Object Notation) is a lightweight data-interchange
format. It is easy for humans to read and write. It is easy for
machines to parse and generate. It is based on a subset of the
JavaScript Programming Language, Standard ECMA-262 3rd Edition -
December 1999. JSON is a text format that is completely language
independent but uses conventions that are familiar to programmers of
the C-family of languages, including C, C++, C#, Java, JavaScript,
Perl, Python, and many others. These properties make JSON an ideal
data-interchange language.
You can parse it using a json parser such as
simpleJson
Jackson
GSon
Try these parsers, if you get stuck with the code then share your code and the problem.

Categories

Resources