numbered?
|
function is_numbered
($aexp)
{return
is_atom($aexp) ? is_number($aexp)
: ( is_eq(car(cdr($aexp)), '+')
|| is_eq(car(cdr($aexp)), 'x')
|| is_eq(car(cdr($aexp)), '^'))
&& is_numbered(car($aexp))
&& is_numbered(car(cdr(cdr($aexp))));
}
|
value
|
function value
($nexp)
{return
is_atom($nexp) ? $nexp
: (is_eq(car(cdr($nexp)), '+') ?
plus(value(car($nexp)),
value(car(cdr(cdr($nexp)))))
: (is_eq(car(cdr($nexp)), 'x') ?
x(value(car($nexp)),
value(car(cdr(cdr($nexp)))))
: power(value(car($nexp)),
value(car(cdr(cdr($nexp)))))));
}
function value
($nexp)
{return
is_atom($nexp) ? $nexp
: (is_eq(operator($nexp), '+') ?
plus(value(first_sub_exp($nexp)),
value(second_sub_exp($nexp)))
: (is_eq(operator($nexp), 'x') ?
x(value(first_sub_exp($nexp)),
value(second_sub_exp($nexp)))
: power(value(first_sub_exp($nexp)),
value(second_sub_exp($nexp)))));
}
|
2nd-sub-exp
|
function second_sub_exp
($aexp)
{return
car(cdr(cdr($aexp)));
}
|
1st-sub-exp
|
// prefix
function first_sub_exp
($aexp)
{return
car(cdr($aexp));
}
// infix
use function car as first_sub_exp;
|
operator
|
// prefix
use function car as operator;
// infix
function operator
($nexp)
{return
car(cdr($nexp));
}
|
sero?
|
function is_sero
($n)
{return
is_nulll($n);
}
|
edd1
|
function edd1
($n)
{return
cons([], $n);
}
|
zub1
|
use function cdr as zub1;
|
blus
|
function blus
($n, $m)
{return
is_sero($m) ? $n
: edd1(blus($n, zub1($m)));
}
|