Re: Which computer language program is best for undergrads?
- From: Jon Harrop <jon@xxxxxxxxxxxxxxxxx>
- Date: Thu, 10 Jul 2008 19:40:55 +0100
Christian Gollwitzer wrote:
A more serious example would be
function p=llsq(A, y, B, c)
% solve the linear least squares problem
% with equality constraints
% min | A p - y | , B p = c
[H, R] = qr(B');
R = R(1:rows(B),:);
AH = A*H;
A1 = AH(:, 1:rows(B));
A2 = AH(:, rows(B)+1:columns(A));
y1=R'\c;
r=A1*y1;
yt = y - r;
z = A2 \ yt;
p = H* [y1; z];
end
which solves a specially LSQ problem. If you compare it to the paper I'm
now lazy to search, you will find that this is an almost verbatim
transliteration of the maths from there.
Again, that relies upon basic features found in many modern languages.
High-level languages IMHO are those that provide datastructures like
lists, matrices, strings... as primitive datatypes together with the
elementary operations.
High-level languages also automate basic functionality like memory
management which, as I understand it, Matlab does not.
I'm not sure what you mean by memory management (GC?). Matlab doesn't have
pointers and you never allocate memory on the heap. Just use your
matrices, cell arrays (=heterogeneous lists in FL speak) as you like and
the memory is allocated automatically.
Matlab does not automate the collection of unused memory, it simply leaks
until it dies or the user explicitly frees memory:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/brh72ex-25.html
That is a hallmark of a low level language and it puts Matlab decades behind
the current state-of-the-art concurrent GCs that underpin the JVM and CLR.
In Matlab you perform matrix operations in symbolic notation like you
would do on paper. Numeric algorithms can often be expressed concisely.
Can a language be high-level if it is good at matrix computations at the
cost of all else?
Some high-level languages are very specialized - take SQL.
I believe you are using a broken definition of "high level". If you take
your definition to the extreme then even the most minimal language (e.g.
Brainf*ck) that lacks almost all modern features is "high level" because it
can do one specialized thing adequately.
Look at The MathWorks' own red-black tree insertion function:
global bt_nil rb_black rb_red
current=rb.tree;
parent=0;
while current~=bt_nil
if key==current.key
return;
end
parent=current;
if key<current.key
current=current.left;
else
current=current.right;
end
end
X=pointer;
X.data=data;
X.key=key;
X.parent=parent;
X.left=bt_nil;
X.right=bt_nil;
X.color=rb_red;
if parent~=0
if key<parent.key
parent.left=X;
rb.size=rb.size+1;
else
parent.right=X;
rb.size=rb.size+1;
end
else
rb.tree=X;
end
while (X~=rb.tree) && (X.parent.color==rb_red)
if X.parent==X.parent.parent.left
Y=X.parent.parent.right;
if Y.color==rb_red
X.parent.color=rb_black;
Y.color=rb_black;
X.parent.parent.color=rb_red;
X=X.parent.parent;
else
if X==X.parent.right
X=X.parent;
rb.tree=rb_rl(rb.tree,X);
end
X.parent.color=rb_black;
X.parent.parent.color=rb_red;
rb.tree=rb_rr(rb.tree,X.parent.parent);
end
else
Y=X.parent.parent.left;
if Y.color==rb_red
X.parent.color=rb_black;
Y.color=rb_black;
X.parent.parent.color=rb_red;
X=X.parent.parent;
else
if X==X.parent.left
X=X.parent;
rb.tree=rb_rr(rb.tree,X);
end
X.parent.color=rb_black;
X.parent.parent.color=rb_red;
rb.tree=rb_rl(rb.tree,X.parent.parent);
end
end
end
rb.tree.color=rb_black;
That is clearly low-level C like code.
Compare with the OCaml/F# (that supports persistence, garbage collection and
is much faster):
let rec ins x t = match t with
E -> R(E, x, E)
| R(a, y, b) ->
if x < y then R(ins x a, y, b) else
if x > y then R(a, y, ins x b) else t
| B(a, y, b) ->
if x < y then match ins x a, y, b with
| R(R(a, x, b), y, c), z, d -> R(B(a, x, b), y, B(c, z, d))
| R(a, x, R(b, y, c)), z, d -> R(B(a, x, b), y, B(c, z, d))
| a, x, b -> B(a, x, b) else
if x > y then match a, y, ins x b with
| a, x, R(R(b, y, c), z, d) -> R(B(a, x, b), y, B(c, z, d))
| a, x, R(b, y, R(c, z, d)) -> R(B(a, x, b), y, B(c, z, d))
| a, x, b -> B(a, x, b) else t
let add x s = match ins x s with
| R(a, y, b) -> B(a, y, b)
| s -> s
Common Lisp provides lists, trees and arrays. Its main problem is a
complete lack of static typing so programmers are unable to have even the
most basic constraints checked and productivity circles the drain as they
live in their debuggers trawling stack traces trying to find the original
of a simple type error.
I've never seriously tried Lisp. After playing with it a while, I got
drunk in thousands of ((())), polish notation and cdr, car which doesn't
make list processing easy.
I've toyed with Lisp as an academic curiosity but I would never try to write
any serious software in it because I learned as a child how dynamic typing
makes it practically impossible to write anything non-trivial correctly.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
.
- References:
- Re: Which computer language program is best for undergrads?
- From: Jon Harrop
- Re: Which computer language program is best for undergrads?
- From: Christian Gollwitzer
- Re: Which computer language program is best for undergrads?
- From: Jon Harrop
- Re: Which computer language program is best for undergrads?
- From: Christian Gollwitzer
- Re: Which computer language program is best for undergrads?
- Prev by Date: Re: Need help with "Space Efficient Linear Time Construction of Suffix Arrays" by Ko And Aluru
- Next by Date: Re: Seed7 (was: Program compression)
- Previous by thread: Re: Which computer language program is best for undergrads?
- Next by thread: Re: recursion with C
- Index(es):
Relevant Pages
|