BitOperationen in GGB?

gwengler shared this question 2 months ago
Answered

Weiß jemand, wie man in GeoGebra elegant z.B.

234 AND 314

234 XOR 314

234 OR 314 etc. ermittelt?

Comments (10)

photo
1

I think you'll need a custom tool for that. First step convert 234 into binary like {1,1,1,0,1,0,1,0}

photo
1

thanx, I know, but I need for double-loop and then this manipulation process is too complex.


In mod-muster1.ggb there is Mod(x ²+y²,a) and I wish for example Mod(x xor y,a) or Mod( x and y,a) etc.

photo
1

Attached are versions for AND and XOR that work reasonably well. I used the Iteration command to compute all the AND-values (or XOR-values) recursively. They are stored in a matrix, so they don't have to be re-computed whenever the value of a changes, instead they are just looked up to for the Mod operation. Computation might take a few seconds for a 201x201 matrix, and I advise to not let such a big matrix show in the Algebra window (my GeoGebra almost always crashed when I did that). There is a variable nmax which sets the size of the matrix, just set it lower if you need to show auxiliary variables. (In the attached files it is currently set to 50 just to be safe. Just set it higher again.)

photo
1

thank you, very clever!

I also have realized the bit-ops without string-transfer, but no idea to make an array of points withit.

photo
1

Yes, that's the natural way to make a bit list, but it's rather slow due to the amount of operations involved. (That's why I used an iteration approach where you don't need the whole bit list.) Creating the point list via those bit lists isn't a problem either.

Attached are 5 different AND-versions. All have nmax set to 20. Set it to 200 and see how long it takes to update.

  1. Mod-Muster-BitAND-Matrix-Sequence.ggb constructs a matrix of AND-values via bit lists, somewhat naively in a single command. It's rather slow.
  2. Mod-Muster-BitAND-Matrix-SequenceImproved.ggb also constructs a matrix of AND-values via bit lists, but avoids re-computing the two bitlists for each pair x,y. Instead the bitlist for each number up to nmax is computed beforehand, so they can be re-used in the matrix computation. It's only slightly faster though.
  3. Mod-Muster-BitAND-Matrix-Iteration.ggb constructs a matrix of AND-values via iteration. Each iteration doubles the size of the matrix. Avoids the need for complete bit representations. Instead numbers are split only in two parts: the lowest bit and the higher part. Bit operations for the higher parts don't have to be computed, they can simply be looked up in the last oteration of the matrix. About twice as fast as the bit list approach.
  4. Mod-Muster-BitAND-Matrix-JS.ggb constructs a matrix of AND-values via JavaScript. (OnUpdate script of nmax.)
  5. JavaScript comes with fast bitwise operators, so the values are computed ultra fast. The script actually produces an Execute-string for the matrix creation and executes it in GeoGebra (because modifying GeoGebra lists via JS is ultra slow). Maybe 50% faster than the iteration approach. (Main hang-up is probably that dealing with a 201x201-matrix is generally not fast in GeoGebra.)
  6. Mod-Muster-BitAND-direct-JS.ggb also uses JavaScript but skips the part of creating the AND-matrix and computes the point list directly. (OnUpdate script of nmax and also a.) About twice as fast as the JS version with the matrix. And fast enough that that the matrix isn't even needed, i.e., changing a doesn't produce a hang-up despite the complete re-computation.

I also attempted to make a version using the spreadsheet, hoping that it might be faster than iteration over the big matrix, but the spreadsheet seems generally slow. Even building a 51x51-matrix took many times longer than 201x201 with a bit list. So I scrapped this approach.

photo
1

thank you very much!

photo
photo
1

Für diese etwas veränderte Fragestellung würde ich es wie im Anhang lösen.

photo
1

Diese Variante kenne ich - siehe BitOperationen.ggb


oder mit JS siehe BitOp-JS.ggb.

Aber wenn ich folgendes Muster machen möchte wird dies zu einem

untauglichen Aufwand:

folge(folge(wenn(Mod(j xor k,m)==0,1,0),j,0,255),k,0,255) m..Modul


Da hätte ich für xor gerne eine fertige Rechenoperation so wie +,-,*,/,^ .

Es ist ja mehr gedacht als ein Wunsch bzw. eine Anregung für eine Erweiterung des Angebots an mathematischen Funktionen.

photo
photo
1

Ich hab mal versucht das als userfunction im CAS zu handeln..

aber Text und UniCode im CAS geht gar net....

z.B. führende Nullen verschwinden auch bei Text

https://www.geogebra.org/m/anv8ymuc

nicht dass Du da noch viel Zeit investierst?

© 2021 International GeoGebra Institute