How to force calculation?
Hi.
I was wondering, is it possible to enforce "simplest form possible" on calculations?
Because when i was messing around with fractions, i noticed that the engine evaluates the fractions as equal (which they also are), but is there a way to enforce the most simple form on an expression? For example the engine evaluates this to true:
3-5+8/6 == -2/3
And this
6/8 == 3/4
Is there a way (or function) to make sure that this evaluates to False, and is only True if it is indeed the most simple form of the fraction?
The same applies to this example:
Simplify(x+2x+6) == x+2x+6
This evaluates to True also, but is there a way to make sure it does not unless the right answer is provided? (6+3x OR 3x+6) ?
Many thanks in advance
Comments (7)
-
repo owner -
reporter Well the "Hold(expr)" did sound like the thing i needed, but i just tried it, and it does not work in my program. Also, i cannot find it here: https://bitbucket.org/axelclk/symja_android_library/src/f4292c0d129d/symja_android_library/doc/functions/?at=master
SameQ is the one i am using now, and
SameQ(Simplify(6/8), 6/8) == True
, which is my problem. I only want SameQ to be true, if the second argument is the most simple answer of the first argument. For example, i want this to be the case:SameQ(Simplify(6/8), 6/8) == False
And
SameQ(Simplify(6/8), 3/4) == True
It did sound like a good answer to use "Hold", such that
SameQ(Simplify(6/8), Hold(6/8)) == False
But it just made everything turn out false, also
SameQ(Simplify(6/8), Hold(3/4)) == False
And i still what that to be true.
-
repo owner In commmit #220ba1f I made some changes for Hold() and HoldForm.
HoldForm(6/8)==6/8
will evaluate to
6/8==3/4
and
Hold(6/8)==3/4
to
Hold(6/8)==3/4
It would probably help if you show your source code, so that on "Java level" it could be easier to get what you want?
-
reporter And does
HoldForm(6/8)===3/4
evaluate to True of False after your changes?In order for me to try it out i would need a ned JAR build with the changes, since i do not have eclipse and ANT here at the moment.
-
repo owner Here you can find the latests Maven Symja snapshot
-
reporter Alright i finally got to tryout the nye core update, and it is not doing what i expected.
i have
HoldForm(3/4) === 3/4
evaluate to False.What i need is that if i call
HoldForm(3/4) === 3/4
is will be True, but if i callHoldForm(6/8) === 3/4
it will evaluate to False, since it is not the most simple form.My Java code is actually just comparing the answer with the result like this:
// instantiate new expression evaluator engine instance ExprEvaluator util = new ExprEvaluator(false, 100); // get correct result by evaluating the formal IExpr result = util.evaluate(expression.getFormal()); // evaulate if answer was correct IExpr comparison = util.evaluate("HoldForm("+getUserAnswer() + ") === " +result.toString() );
I hope that helps to see what i mean :)
-
repo owner - changed status to closed
Please use the Github issue tracker to open a new issue if this issue shouldn't be closed Github issues
- Log in to comment
Not sure what you want to achieve?
Do you have some sample codes?
Did you try Hold() for letting an expression unevaluated?
Did you try Trace() for getting the evaluation steps