Commit 9fa3f1d7 authored by Morten Welinder's avatar Morten Welinder

Deriv: cleanups.

parent adfa5e70
......@@ -1751,16 +1751,17 @@ gnumeric_sumsq (GnmFuncEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
GNM_ERROR_VALUE);
}
// Construct an equivalend expression
static GnmExpr const *
gnumeric_sumsq_deriv (GnmFunc *func,
GnmExpr const *expr, GnmEvalPos const *ep,
gnumeric_sumsq_equiv (GnmExpr const *expr, GnmEvalPos const *ep,
GnmExprDeriv *info)
{
GnmExprList *l, *args = gnm_expr_deriv_collect (expr, ep, info);
GnmExpr const *res;
GnmExpr const *sqsum;
GnmFunc *fsum = gnm_func_lookup_or_add_placeholder ("SUM");
GnmExprList *l, *args;
GnmFunc *fsum = gnm_func_lookup ("SUM", NULL);
if (!fsum) return NULL;
args = gnm_expr_deriv_collect (expr, ep, info);
for (l = args; l; l = l->next) {
GnmExpr const *e = l->data;
GnmExpr const *ee = gnm_expr_new_binary
......@@ -1770,11 +1771,21 @@ gnumeric_sumsq_deriv (GnmFunc *func,
l->data = (gpointer)ee;
}
sqsum = gnm_expr_new_funcall (fsum, args);
res = gnm_expr_deriv (sqsum, ep, info);
gnm_expr_free (sqsum);
return gnm_expr_new_funcall (fsum, args);
}
return res;
static GnmExpr const *
gnumeric_sumsq_deriv (GnmFunc *func,
GnmExpr const *expr, GnmEvalPos const *ep,
GnmExprDeriv *info)
{
GnmExpr const *sqsum = gnumeric_sumsq_equiv (expr, ep, info);
if (sqsum) {
GnmExpr const *res = gnm_expr_deriv (sqsum, ep, info);
gnm_expr_free (sqsum);
return res;
} else
return NULL;
}
/***************************************************************************/
......
......@@ -552,9 +552,9 @@ gnm_expr_deriv (GnmExpr const *expr,
case GNM_EXPR_OP_EXP: {
COMMON_BINARY_START
GnmFunc *fln = gnm_func_lookup ("ln", NULL);
GnmValue const *vb = gnm_expr_get_constant (b);
if (vb && VALUE_IS_FLOAT (vb)) {
GnmExpr const *bm1 = gnm_expr_new_constant (value_new_float (value_get_as_float (vb) - 1));
gnm_float cb;
if (is_any_const (b, &cb)) {
GnmExpr const *bm1 = gnm_expr_new_constant (value_new_float (cb - 1));
GnmExpr const *t1 = mexp (a, 1, bm1, 0);
gnm_expr_free (db);
return mmul (mmul (b, 1, t1, 0), 0, da, 0);
......@@ -575,7 +575,7 @@ gnm_expr_deriv (GnmExpr const *expr,
case GNM_EXPR_OP_FUNCALL: {
GnmFunc *f = gnm_expr_get_func_def (expr);
GnmExpr const *res = gnm_func_derivative (f, expr, ep, info);
GnmExpr const *opt = optimize (res);
GnmExpr const *opt = res ? optimize (res) : NULL;
if (opt) {
gnm_expr_free (res);
res = opt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment