caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Side effect
@ 2002-08-08 22:40 Nicolas FRANCOIS
  2002-08-09  6:43 ` Florian Hars
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas FRANCOIS @ 2002-08-08 22:40 UTC (permalink / raw)
  To: Caml List

Thanks for the tip on stdout, I found the problem. Ocamldebug had me
discover another bug (a copy-paste bug ;-), but I'm stuck on this one :

  let cherche_pivot m fllig flcol =
    try
      for i = 0 to D.lignes - 1 do
	if fllig.(i)
	then
	  for j = 0 to D.colonnes - 1 do
	    if flcol.(j)
	    then
	      if A.(==) m.(i).(j) A.zero
	      then ()
	      else raise (Pivot_trouve (i,j))
	  done
      done;
      raise Plus_de_pivot
    with Pivot_trouve (i,j) -> (i,j)

  let applique_pivot_ligne m fllig flcol i j div =
    let m' = Array.copy m
    and x = m.(i).(j)
    in
      for i' = 0 to D.lignes - 1 do
	if fllig.(i')
	then
	  let y = m'.(i').(j) in
	    for j' = 0 to D.colonnes - 1 do
	      if flcol.(j')
	      then m'.(i').(j') <-
		A.(//) (A.(--)
			  (A.( ** ) x m'.(i').(j'))
			  (A.( ** ) y m'.(i).(j'))) div
	    done;
	    m'.(i').(j) <- A.zero;
      done;
      m'
	
  let pivot_ligne_sans_echange m =
    let m' = Array.copy m
    and fllig = Array.make D.lignes true
    and flcol = Array.make D.colonnes true
    and divisor = A.one
    in
    let rec plse_aux mat fl fc div =
      try
	let (i,j) = cherche_pivot mat fl fc
	in
	  fl.(i) <- false;
	  fc.(j) <- false;
	  let mat' = applique_pivot_ligne mat fl fc i j div in
	    plse_aux mat' fl fc mat'.(i).(j)
      with Plus_de_pivot -> mat
    in
      plse_aux m' fllig flcol A.one	
end

It's just a fraction free Gauss reduction without lines exchanges. It
works :

  let m = Matrice_Z.parse
    (Stream.of_string
       "[[ 3, 4, -2, 1, -2],[ 1, -1, 2, 2, 7],[ 4, -3, 4, -3, 2],[ -1, 1,
        6, -1, 1]]");;
  Matrice_Z.print m;;

prints

  (  3  4  -2  1  -2  )
  (  1  -1  2  2  7  )
  (  4  -3  4  -3  2  )
  (  -1  1  6  -1  1  )

  let m' = Pivot_Z.pivot_ligne_sans_echange m;;
  Matrice_Z.print m';;

gives the correct 

  (  3  4  -2  1  -2  )
  (  0  -7  8  5  23  )
  (  0  0  20  72  159  )
  (  0  0  0  -556  -1112  )

Trouble is
  
  Matrice_Z.print m';;

answers

  (  3  4  -2  1  -2  )
  (  0  -7  8  5  23  )
  (  0  0  20  72  159  )
  (  0  0  0  -556  -1112  )

So matrix m was modified. But I work on a copy of m in
Pivot_Z.pivot_ligne_sans_echange. What's the problem doc ?

\bye

-- 

                   Nicolas FRANCOIS
            http://nicolas.francois.free.fr
 A TRUE Klingon programmer does NOT comment his code
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-09 12:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-08 22:40 [Caml-list] Side effect Nicolas FRANCOIS
2002-08-09  6:43 ` Florian Hars
2002-08-09 11:27   ` Nicolas FRANCOIS
2002-08-09 12:08     ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).