present state of unevaluated conditionals, was: Handling branch cuts ...
Subject: present state of unevaluated conditionals, was: Handling branch cuts ...
From: Robert Dodier
Date: Sun, 13 Feb 2005 18:20:58 -0800 (PST)
--- Stavros Macrakis wrote:
> All you say is true. But if nothing is known about the value of x,
> and you do ev(expr,nouns), instead of getting an unevaluated
> conditional back, you will get an error. Not really satisfactory!
Well, the error can be turned off via the flag prederror.
(%i1) prederror: false$
(%i2) if a > b then a else b;
(%o2) if unknown then a else b
Ugh! Here's a 1-line patch to preserve the unevaluated condition
(and also evaluate the alternatives).
This is currently line 2554 in src/mlisp.lisp --
- (v (return (list* '(mcond) v (mapcar #'meval-atoms (cdr u))))))))
+ (v (return (list* '(mcond) (car u) (mapcar #'meval1 (cdr u))))))))
This is much nicer, I think --
(%i1) load("src/mlisp.lisp")$
(%i2) prederror: false$
(%i3) expr: if a > b then if a > c then a else c else if b > c then b
else c;
(%o3) if a > b then (if a > c then a else c)
else (if b > c then b else c)
(%i4) assume (a > b)$
(%i5) expr, nouns;
(%o5) if a > c then a else c
(%i6) forget (a > b)$
(%i7) assume (a > c)$
(%i8) expr, nouns;
(%o8) if a > b then a else (if b > c then b else c)
(%i9) forget (a > c)$
(%i10) expr, nouns;
(%o10) if a > b then (if a > c then a else c)
else (if b > c then b else c)
(%i11) assume (b < c)$
(%i12) expr, nouns;
(%o12) if a > b then (if a > c then a else c) else c
(%i13) assume (a > c)$
(%i14) expr, nouns;
(%o14) a
All that seems as it should be. Also the following
yields the expected plots --
(%i15) f(x) := if x < 0 then -x else sqrt(x);
(%o15) f(x) := if x < 0 then - x else sqrt(x)
(%i16) plot2d (if x > 1 then log(x) else exp(x), [x, -1, 3])$
(%i17) plot2d (f(x), [x, -2, 2]);
run_testsuite() finds no unexpected errors, which
doesn't prove much although it is evidence for the
absence of unintended side-effects.
Well, that seems like a happy situation. Comments?
Robert Dodier
__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250