[system] / trunk / pg / lib / Value / Formula.pm Repository:
ViewVC logotype

Log of /trunk/pg/lib/Value/Formula.pm

Parent Directory Parent Directory


Links to HEAD: (view) (download) (as text) (annotate)
Sticky Revision:

Revision 3716 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Oct 16 03:37:17 2005 UTC (14 years, 2 months ago) by dpvc
File length: 16143 byte(s)
Diff to previous 3677
In the past, when Value objects were inserted into strings, they would
automatically include parentheses so that if you had $f equal to 1+x
and $g equal to 1-x, then Formula("$f/$g") would mean (1+x)/(1-x)
rather than 1+(x/1)-x, which is what would happen as a straing string
substitution.

The problem is that this would also happen for real numbers, vectors,
and everything else, even when it wasn't necessary.  So if $x=Real(3),
then "Let x = $x" would be "Let x = (3)".

I have changed the behavior of the string concatenation for Value
objects so that parentheses are only added in a few cases: for
Formulas, Complex numbers, and Unions.  This makes the other Value
objects work more like regular variables in strings, but might cause
some problems with strings that are used as formulas.  For example, if
$a = Real(-3), then "x + 2 $a" will become "x + 2 -3", or "x-1" rather
than the expected "x - 6".  (The old approach would have made it "x +
2 (-3)" which would have worked properly).  For the most part, it is
easier to use something like "x + 2*$a" or even "x" + 2*$a in this
case, so the extra trouble of having to avoid parentheses when you
really meant to substitute the value into a string didn't seem worth
it.

Revision 3677 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Oct 1 01:10:27 2005 UTC (14 years, 2 months ago) by dpvc
File length: 16141 byte(s)
Diff to previous 3613
Allow context to override object class used to create formula objects
(so that things like ImplicitPlane can create instances of themselves
automatically when needed).

This mechanism needs to be enlarged to encompass the other Value
object classes as well (like the Context()->{parser}{...} hash).

The real problem is that the List object probably shouldn't create a
formula returning a list when it is passed formulas, since there
really isn't much need for a formula returning a list to be
autogenerated (you can create one by hand using Formula if needed).

Right now, ALL the Value objects make themselves into Formulas when
one of their entries is a formula.  For example, Point(1,"x") produces
the same thing as Formula("(1,x)"), and List(1,"x") is the same as
Formula("1,x").  This is good for points, but not so good for lists.
And it might sometimes be nice to have a Vector of Formulas, or a
Matrix with Formula entries (rather than Formulas returning Vectors or
Matrices).  But this would require some serious changes internally in
the Value objects, which make assumptions about their values being
constant.  Changing that will be for another day...

Revision 3613 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Sep 12 23:28:37 2005 UTC (14 years, 3 months ago) by dpvc
File length: 15892 byte(s)
Diff to previous 3523
Fixed an error where scalar() was used on a hash ref.
Fixed a misfeature where operations on formulas could return Value
objects of other classes; they should always return formulas, even
when the formula is constant.

Revision 3523 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 13 22:38:39 2005 UTC (14 years, 4 months ago) by dpvc
File length: 15888 byte(s)
Diff to previous 3517
Added canBeInUnion and isSetOfReals methods to the Parser package
(similar to the ones in the Value package), replacing the
canBeInterval flag and other ad hoc checks.

Removed ability to form interval like [a] now that we have sets.

Revision 3517 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 13 21:31:46 2005 UTC (14 years, 4 months ago) by dpvc
File length: 15897 byte(s)
Diff to previous 3515
Pass the canBeInUnion call on to the Formula's root node

Revision 3515 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 13 20:55:35 2005 UTC (14 years, 4 months ago) by dpvc
File length: 15848 byte(s)
Diff to previous 3487
Make formulas that produce lists get default open and close parens,
and have them retained in Formula() results.

Revision 3487 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Aug 12 17:09:42 2005 UTC (14 years, 4 months ago) by dpvc
File length: 15641 byte(s)
Diff to previous 3470
Changed how Intervals implement the requireParenMatch flag for the
interval and union answer checker.  (Use a Context flag rather than a
flag on the interval itself.)  Moved the getFlag method from
Formula.pm to Value.pm so it can be used by any object class.  New
feature where classes can add more context flags to set (and reset
after the answer checker runs).

Revision 3470 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Aug 11 14:25:53 2005 UTC (14 years, 4 months ago) by dpvc
File length: 16073 byte(s)
Diff to previous 3370
Changes needed for new Set object, and moving of string, TeX and perl
methods to Value.pm

Revision 3370 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jul 12 22:29:53 2005 UTC (14 years, 5 months ago) by dpvc
File length: 15869 byte(s)
Diff to previous 3369
A first pass at making parser error messages localizable.  The
Context()->{error}{msg} hash can be used to specify translations of
the standard messages.  For example,

    Context()->{error}{msg}{'Division by zero'} = "Don't divide by zero, dude!";
    Context()->{error}{msg}{'Function '%s' has too many inputs'} =
        "You passed too many arguments to '%s'";

(I didn't translate into another language, here, but you could do
that, too.)

The msg hash could also be used within answer checkers to make certain
answer messages more appropriate for the given type of expected answer.

Revision 3369 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Jul 12 21:05:37 2005 UTC (14 years, 5 months ago) by dpvc
File length: 15882 byte(s)
Diff to previous 3342
Fixed various perl compiler warnings (due to extra "my", and so on).

Revision 3342 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Jul 4 15:53:26 2005 UTC (14 years, 5 months ago) by dpvc
File length: 15885 byte(s)
Diff to previous 3339
Better messages when adaptive parameters are too big.

Revision 3339 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Jul 4 15:22:22 2005 UTC (14 years, 5 months ago) by dpvc
File length: 15750 byte(s)
Diff to previous 3296
Don't use the overloaded Real class for doing adaptive parameter
checks (use non-fuzzy checks, since we are checking the fuzziness by hand).

Revision 3296 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Jun 16 04:03:40 2005 UTC (14 years, 6 months ago) by dpvc
File length: 15737 byte(s)
Diff to previous 3264
Fixed a problem with auto-generated functions getting an incomplete
variable list.

Revision 3264 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Jun 5 23:18:01 2005 UTC (14 years, 6 months ago) by dpvc
File length: 15804 byte(s)
Diff to previous 3261
Fix some incorrect calls when the promoting types to higher precedence
object types.

Revision 3261 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Jun 4 13:50:41 2005 UTC (14 years, 6 months ago) by dpvc
File length: 15595 byte(s)
Diff to previous 3258
Avoid possible infinite loop with length and typeref calls.

Revision 3258 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Jun 3 19:14:00 2005 UTC (14 years, 6 months ago) by dpvc
File length: 15547 byte(s)
Diff to previous 3257
Better control over number of points that can be undefined, and
new ability to specify required test points plus additional random
ones.  (Previously, if you set the test points, no random points were
generated.)  For example:

     $f = Formula("(x^2-1)/(x-1)");
     $f->{test_at} = [[1]];  # test at x=1 plus random points

as opposed to

     $f->{test_points} = [[-1],[0],[1]];

which tests only the points x = -1, x = 0 and x = 1.

Revision 3257 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Jun 2 22:50:24 2005 UTC (14 years, 6 months ago) by dpvc
File length: 15217 byte(s)
Diff to previous 3256
Modified the Formula answer checker to allow checking of points where
the functions are undefined (i.e., attempt to check that the domains
agree).  This can be enabled by setting the checkundefinedPoints flag
in the Context(), or in the formula itself.  Test points where the
function is undefined will be retained and the student's answer will
have to be undefined at the same points.  If the points are selected
at random, the points where the function is undefined are kept in
addition to the ones where it is defined, so the required number of
test points where the function IS defined will still need to be
found.  The number of undefined points can be up to the number of
defined points.  This number can be reduced by setting the
max_undefined flag.  If you want to guarantee that a specific
undefined point be tested, you can provide that point using the
test_points field of the formula.  For example:

     Context()->flags->set(checkUndefinedPoints=>1);
     $f = Formula("(x^2-1)/(x-1)");
     $f->{test_points} = [[-1],[0],[1],[2]];
     ANS($f->cmp);

will guarantee that the singularity at x=1 is tested, so the answer
x+1 will not be marked as correct.

If an answer matches at all the test points where the functions are
both defined, but some of the undefind points differ between the two
functions, the answer checker will generate an error message
indicating that the domains of the functions don't agree.  (This is
ONLY generated with the functions match except for that.)  This can be
controlled by setting the showDomainErrors flag in the formula's cmp()
call:

     ANS($f->cmp(showDomainErrors=>0));

The default is to show these errors.

Revision 3256 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Jun 2 19:53:06 2005 UTC (14 years, 6 months ago) by dpvc
File length: 14562 byte(s)
Diff to previous 3218
Fixed an accidental hard-coded operation from always being "add" to
being the correct operation when promoting the operations to an object
of higher precedence.  (But since formulas are normally the highest
precedence, this will never have occurred.)

Revision 3218 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Apr 29 02:37:13 2005 UTC (14 years, 7 months ago) by dpvc
File length: 14513 byte(s)
Diff to previous 3216
Fixed a bug with adaptive parameters where the relative tolerance
was not being properly computed.  This allowed large constants to be
treated as correct when they shouldn't be.

Revision 3216 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Apr 27 21:29:10 2005 UTC (14 years, 7 months ago) by dpvc
File length: 13033 byte(s)
Diff to previous 3192
Use correct form of "x" with lists (rather than hack using split()).

Revision 3192 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Wed Mar 16 13:30:28 2005 UTC (14 years, 9 months ago) by dpvc
File length: 13063 byte(s)
Diff to previous 3177
Update the overloaded operators so that they can be overridden by
subclasses of the predefined object classes.  This involves calling
the objects method rather than using a hard reference to the routine
in the parent class.

Also, change the name of the string comparison routine to
compare_string to avoid conflicts with cmp that is used to produce the
answer checker for the class.

Finally, in Value.pm, promotePrecedence no longer has to do fancy
footwork to get "special" precedence to work (this was a hack to get
around the misfeature of the overloaded operators -- now that that is
being handled correctly, there is no need for it).

Revision 3177 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Feb 18 00:04:09 2005 UTC (14 years, 9 months ago) by dpvc
File length: 12853 byte(s)
Diff to previous 3174
Missed one situation when making the previous update.  Fixed it.

Revision 3174 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Thu Feb 17 16:12:45 2005 UTC (14 years, 10 months ago) by dpvc
File length: 12853 byte(s)
Diff to previous 2800
Fixed it so that direct calls to the add, sub, mult, etc functions
would work as expected (even though there is no need to call them directly).

Revision 2800 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Sep 19 14:27:39 2004 UTC (15 years, 2 months ago) by dpvc
File length: 12853 byte(s)
Diff to previous 2688
Added isZero and isOne checks for Parser::Value objects (i.e., for
constants within formulas).  These now correctly handle vector and
matrices, in particular.  The isOne and isZero checks are used in the
reduce() method to simplify formulas.

Revision 2688 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Aug 27 19:42:59 2004 UTC (15 years, 3 months ago) by dpvc
File length: 12780 byte(s)
Diff to previous 2687
Added in functMaxConstantOfIntegration support in the adaptive
parameter answer checking.  Also added a flag to the formula answer
checker that allows checking a formula up to a constant (for
integration problems).  This really just adds a new parameter to the
context and adds that to the formula, so there is nothing deep about
this.

	ANS(Formula("2x")->cmp(upToConstant=>1));

Finally, don't look for adaptive parameters if they aren't actually
used in the professor's formula (even if they are defined).

Revision 2687 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Fri Aug 27 00:28:27 2004 UTC (15 years, 3 months ago) by dpvc
File length: 12344 byte(s)
Diff to previous 2678
Added ability to have linear adaptive parameters in the function
answer checker.  It only works for real-valued functions, though.
To use a parameter, use

       Context()->variables->add(a=>'Parameter');

and then use 'a' as a variable within your answer.  The student will
not be allowed to enter the parameter, but the professor will.

Note that the correct answer will show the full professor's answer,
including the parameters, even though the student can't type it.  Is
this the right behaviour?

Revision 2678 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 23 23:55:37 2004 UTC (15 years, 3 months ago) by dpvc
File length: 10631 byte(s)
Diff to previous 2671
Modified the parser so that the classes for the various object
constructors are stored in the context table rather than hard-coded
into the parser.  That way, you can override the default classes with
your own.  This gives you even more complete control to modify the
parser.  (You had been able to replace the definitions of operators,
functions and list-like objects, but could not override the behaviour
of numbers, strings, variables, and so on.  Now you can.)

This effects most of the files, but only by changing the name of the
calls that create the various objects.

There are also a couple of other minor fixes.

Revision 2671 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 22 21:18:06 2004 UTC (15 years, 3 months ago) by dpvc
File length: 10559 byte(s)
Diff to previous 2669
Fixed some inconsistencies between handing of matrices within the
parser and Value packages.  Added a predefined Matrix context.

Revision 2669 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 22 15:42:50 2004 UTC (15 years, 3 months ago) by dpvc
File length: 10521 byte(s)
Diff to previous 2668
Made the granularity of the test-point intervals be a parameter that
can be set on a global or variable-by-variable basis, so this is now
controlable from the .pg file.  For example:

            Context("Numeric")->variables->are(
              k=>{limits=>[1,10], resolution=>1},
              x=>{limits=>[-2,2], granularity=>1000},
            );

will make k be a variable that will only take on integer values
between 1 and 10, and x a variable that will take on one of 1000
different values evenly spaced between -2 and 2 (so resolution is
4/1000 in this case).

These parameters can also be set for an individual formula:

           $f = Formula("k^2-1");
           $f->{resolution} = 1;
           $f->{limits} = [0,10];

Revision 2668 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 22 02:55:38 2004 UTC (15 years, 3 months ago) by dpvc
File length: 10149 byte(s)
Diff to previous 2666
Fixed TeX output of Matrices to use \array rather than \matrix for
matrices with formulas as entries (this had already been fixed for
constant matrices).  Made intervals produce formulas when of of the
endpoints is a formula.  Removed unneeded comment.

Revision 2666 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 22 00:56:32 2004 UTC (15 years, 3 months ago) by dpvc
File length: 10204 byte(s)
Diff to previous 2629
Formulas can now be compared even if their variables are complex
numbers, or even points or vectors!  This makes it possible to ask
students for complex functions like z^2+i and so on.

You can specify limits for variables either via
Context()->variables->set(x=>{limits=>[0,1]})  (for reals) or
Context()->variables->set(z=>{limits=>[[-2,2],[0,1]]}) (for complexes).
Similarly for points and vectors (where the number of sub arrays
depends on the dimension).  You can also give the limits for a
specific formula by assigning to its ->{limits} field:

    $f = Formula("sqrt(x-10)");
    $f->{limits} = [10,12];

There are now named variable types for 'Point2D', 'Point3D',
'Vector2D' and 'Vector3D', in addition to 'Real' and 'Complex'.
You can also specify a variable type by giving an explicit instance of
a value of the given type.  E.g.

    Context()->variables->add(x=>'Real',y=>0);     # two real variables
    Context()->variables->add(z=>'Complex',w=>i);  # two complexes
    Context()->variables->add(r=>Vector(0,0,0));   # a vector in R^3
    Context()->variables->add(X=>'Vector3D');      # a vector in R^3

There still needs to be more error checking in processing
user-supplied limits, but I'm not sure how much overhead is worth it.

Revision 2629 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Tue Aug 17 02:01:27 2004 UTC (15 years, 4 months ago) by dpvc
File length: 8353 byte(s)
Diff to previous 2625
Fixed a number of minor problems with creating perl functions from
formulas (this is done automatically as part of the function answer
checker, so is showing up now that I have that checker in place).

Also improved error messages in the function answer checker, and fixed
a bug when students enter a constant list or union when the answer
checker expects formulas.

Revision 2625 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 16 18:35:12 2004 UTC (15 years, 4 months ago) by dpvc
File length: 8351 byte(s)
Diff to previous 2624
Added string comparison to all Value object classes (to compare the
string value of an object to another string).

Overloaded perl '.' operator to do dot product when the operands are
formulas returning vectors.  (Part of the auto-generation of
formulas).

A few improvements to real and complex class output results.

Made Union class slightly more robust and removed need for makeUnion
method other than in the Union itself.

Revision 2624 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Mon Aug 16 13:44:45 2004 UTC (15 years, 4 months ago) by dpvc
File length: 8052 byte(s)
Diff to previous 2622
Added support for unorderd list or formulas with partial credit.
Fixed type mismatch reporting in formula answer checker.
Fixed an error with Unions producing incorrect perl versions under
some circumstances.

Revision 2622 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 15 22:46:57 2004 UTC (15 years, 4 months ago) by dpvc
File length: 7897 byte(s)
Diff to previous 2621
Created the first draft of the Parser's function answer checker.  Some
work still needs to be done, in particular, type mismatches are not
being reported, and lists are being processed only as ordered lists
with no partial credit.

This doesn't implement everything from fun_cmp.  In particular, there
is no support for parameter matching at the moment.  This will have to
be added, but I'm not quite sure how to do it when the function's
return value is not a real number (e.g., an interval).

On the other hand, this checker is more forgiving about domain errors:
if tries a point where the professor's function is not defined, it
ignores that one and looks for another (until it decides it can't find
one).  Once it has these points, it tries them on the student's
answer, and if the student's function is undefined, then the student
answer is wrong (since it is not defined somewhere that the
professor's funciton is).  This avoids the "Error evaluating student
function at ..." messages, which just confused most students anyway.

Revision 2621 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sun Aug 15 17:05:41 2004 UTC (15 years, 4 months ago) by dpvc
File length: 3677 byte(s)
Diff to previous 2606
Improved error messages, particularly when the student enters a
formula in an answer that should be constant, and also for incorrect
answers in lists of answers.  There are a few other miscellaneous output
improvements as well.

Revision 2606 - (view) (download) (as text) (annotate) - [select for diffs]
Modified Sat Aug 14 11:25:47 2004 UTC (15 years, 4 months ago) by dpvc
File length: 3508 byte(s)
Diff to previous 2558
Can now specify that the objects stringify themselfs in their TeX
forms rather than their answer-string forms.  This makes it easier to
use the objects in the text of a problem (without having to call ->TeX
explicitly each reference).

Use

       Context()->texStrings

to start outputting TeX strings, and

      Context()->normalStrings

to switch back.

Revision 2558 - (view) (download) (as text) (annotate) - [select for diffs]
Added Wed Jul 28 20:32:33 2004 UTC (15 years, 4 months ago) by sh002i
File length: 3573 byte(s)
merged changes from rel-2-1-a1 -- stop using that branch.

This form allows you to request diffs between any two revisions of this file. For each of the two "sides" of the diff, enter a numeric revision.

  Diffs between and
  Type of Diff should be a

Sort log by:

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9