Automatic Equation and Inequation evaluation.

monarch_dodra monarchdodra at gmail.com
Sat Jun 15 07:42:36 PDT 2013


On Saturday, 15 June 2013 at 13:23:07 UTC, Carlos wrote:
> On Saturday, 15 June 2013 at 12:36:26 UTC, monarch_dodra wrote:
>> On Saturday, 15 June 2013 at 11:44:03 UTC, Carlos wrote:
>>> On Saturday, 15 June 2013 at 08:46:13 UTC, John Colvin wrote:
>>>> On Saturday, 15 June 2013 at 02:05:00 UTC, Carlos wrote:
>>>>> I'm interested in this kind of functionalities; Does D have
>>>>> something on this ?
>>>>>
>>>>> I thought about something like a "eval" function that would 
>>>>> use
>>>>> specified algorithms.
>>>>> something likes this
>>>>>
>>>>> import std.stdio, std.math, std.eval;
>>>>>
>>>>> void main()
>>>>> {
>>>>> eval(Real; a+b^^x+c=56){
>>>>> algor.brute(&result);
>>>>>    }
>>>>> writeln("Positive value is : ", result);
>>>>> }
>>>>
>>>> It's not clear what that would do from your example. I 
>>>> presume a, b and c are defined somewhere and eval solves for 
>>>> x?
>>>
>>> algor.brute does the work. IF you know that algorithm you 
>>> would know what it does.
>>> Another question would be if this way of coding makes sense 
>>> to you.
>>>
>>> This is what the "eval" function does ( in theory ), It takes 
>>> The words : Real, Rational, Irrational or R, Q , Q' and from 
>>> there is defined which numerical group is going to be used 
>>> for the evaluation. Then it identifies the operators and 
>>> variables and defines the equation in a format like a text 
>>> format with a end file character in the end so equations can 
>>> be as long as you want. After that between {algor.(name)} in 
>>> name you call the algorithm you want to use for the 
>>> evaluation there can be predefined algorithm with D but maybe 
>>> you can define your own algorithms.
>>>
>>> What do you think does this makes sense or would you 
>>> implement it other way ?
>>
>> D provides no such thing. AFAIK, there is nothing in Phobos 
>> provided that does it either.
>>
>> It should be doable, where the second argument is a string. 
>> Something like:
>> auto eq = Equation(Real, "a+b^^x+c=56");
>> auto result = Equation.brute();
>>
>> I think it would quite a specialized numerical library though, 
>> so I don't think it would find its way into the standard 
>> library.
>>
>> I'm not sure any such D Library exists. You'll either have to 
>> port an existing library, or link with a C/C++ existing 
>> library.
>
> OK but if developed it would be included in D ? Right ? It 
> would be very useful I think.

Depends what you mean by "included in D" ? In the standard 
library, I wouldn't know (but I don't think so). But that doesn't 
mean it couldn't be distributed as a trusted and reliable third 
party library.


More information about the Digitalmars-d mailing list