Maxima – 204 – Definire funzioni – 5

oTWI

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.613.

compfile (filename, f_1, ..., f_n)
compfile (filename, functions)
compfile (filename, all)
Translates Maxima functions into Lisp and writes the translated code into the file filename.

compfile(filename, f_1, ..., f_n) translates the specified functions. compfile (filename, functions) and compfile (filename, all) translate all user-defined functions.

The Lisp translations are not evaluated, nor is the output file processed by the Lisp compiler. translate creates and evaluates Lisp translations. compile_file translates Maxima into Lisp, and then executes the Lisp compiler.

See also translate, translate_file, and compile_file.

compile (f_1, ..., f_n)
compile (functions)
compile (all)
Translates Maxima functions f_1, ..., f_n into Lisp, evaluates the Lisp translations, and calls the Lisp function COMPILE on each translated function. compile returns a list of the names of the compiled functions.

compile (all) or compile (functions) compiles all user-defined functions.

compile quotes its arguments; the quote-quote operator '' defeats quotation.

Compiling a function to native code can mean a big increase in speed and might cause the memory footprint to reduce drastically. Code tends to be especially effective when the flexibility it needs to provide is limited. If compilation doesn’t provide the speed that is needed a few ways to limit the code’s functionality are the following:

  • If the function accesses global variables the complexity of the function can be drastically be reduced by limiting these variables to one data type, for example using mode_declare or a statement like the following one: put(x_1, bigfloat, numerical_type)
  • The compiler might warn about undeclared variables if text could either be a named option to a command or (if they are assigned a value to) the name of a variable. Prepending the option with a single quote ' tells the compiler that the text is meant as an option.

define (f(x_1, ..., x_n), expr)
define (f[x_1, .--, x_n], expr)
define (f[x_1, ..., x_n] (y_1, ..., y_m ), expr)
define (funmake (f, [x_1, ..., x_n], expr)
define (arraymake (f, [x_1, ..., x_n], expr)
define (ev (expr_1), expr_2)
Defines a function named f with arguments x_1, ..., x_n and function body expr.

define always evaluates its second argument (unless explicitly quoted). The function so defined may be an ordinary Maxima function (with arguments enclosed in parentheses) or an array function (with arguments enclosed in square brackets).

When the last or only function argument x_n is a list of one element, the function defined by define accepts a variable number of arguments. Actual arguments are assigned one-to-one to formal arguments x_1, ..., x_(n - 1), and any further actual arguments, if present, are assigned to x_n as a list.

When the first argument of define is an expression of the form f(x_1, ..., x_n) or f[x_1, ..., x_n], the function arguments are evaluated but f is not evaluated, even if there is already a function or variable by that name.

When the first argument is an expression with operator funmake, arraymake, or ev, the first argument is evaluated; this allows for the function name to be computed, as well as the body.

All function definitions appear in the same namespace; defining a function f within another function g does not automatically limit the scope of f to g. However, local(f) makes the definition of function f effective only within the block or other compound expression in which local appears.

If some formal argument x_k is a quoted symbol (after evaluation), the function defined by define does not evaluate the corresponding actual argument. Otherwise all actual arguments are evaluated.

See also := and ::=.

define always evaluates its second argument (unless explicitly quoted).

(%i1) expr : cos(y) - sin(x);
(%o1)                           cos(y) - sin(x)
(%i2) define (F1 (x, y), expr);
(%o2)                     F1(x, y) := cos(y) - sin(x)
(%i3) F1 (a, b);
(%o3)                           cos(b) - sin(a)
(%i4) F2 (x, y) := expr;
(%o4)                          F2(x, y) := expr
(%i5) F2 (a, b);
(%o5)                           cos(y) - sin(x)

The function defined by define may be an ordinary Maxima function or an array function.

(%i6) define (G1 (x, y), x.y - y.x);
(%o6)                      G1(x, y) := x . y - y . x
(%i7) define (G2 [x, y], x.y - y.x);
(%o7)                       G2     := x . y - y . x
                              x, y

When the last or only function argument x_n is a list of one element, the function defined by define accepts a variable number of arguments.

(%i8) define (H ([L]), '(apply ("+", L)));
(%o8)                       H([L]) := apply("+", L)
(%i9) H (a, b, c);
(%o9)                              c + b + a

When the first argument is an expression with operator funmake, arraymake, or ev, the first argument is evaluated.

(%i10) [F : I, u : x];
(%o10)                              [I, x]
(%i11) funmake (F, [u]);
(%o11)                               I(x)
(%i12) define (funmake (F, [u]), cos(u) + 1);
(%o12)                        I(x) := cos(x) + 1
(%i13) define (arraymake (F, [u]), cos(u) + 1);
(%o13)                         I  := cos(x) + 1
                                x
(%i14) define (foo (x, y), bar (y, x));
(%o14)                      foo(x, y) := bar(y, x)
(%i15) define (ev (foo (x, y)), sin(x) - cos(y));
(%o15)                   bar(y, x) := sin(x) - cos(y)

AI, innovazioni e blockchain – 61

Rassegna dedicata all’amico Oppy che ci ha appena lasciato; grazie Oppy ❤️

000Ev6ai7Ny

Le point de vue de Garry Kasparov sur l’#IA, l’Homme, et leur futur commun
artificial intelligence
::: BenjaminDHONT

Google Fiber Abandoning Louisville Residents With Two Months Notice
Web, Internet
::: Slashdot

AI Hears Your Anger in 1.2 Seconds
artificial intelligence
::: Slashdot

Data is everything
dati, raccolta
::: b4rtowski

A huge goodie bag of new quilc issues to hack away on
quantum computing | lisp(s)
::: stylewarning

Apollo Thread
innovazioni, futuro
::: Symbo1ics

This story by @chengela on AI in life insurance pricing quotes @aselbst, @cybersimplesec, and me. It’s a terrific intro to the issues. I am working on a paper that covers all this and more, but for now here is a short(ish) thread
artificial intelligence
::: RickSwedloff

Teenager Builds Himself a Robotic Prosthetic Arm Using Lego Pieces
robots
::: Slashdot

Facebook Acquires Visual Shopping Startup To Bolster AI Work
artificial intelligence
::: Slashdot

“The end of Moore’s Law has been predicted so many times that rumors of its demise have become an industry joke.” At the risk of being the butt of such a joke now or in the distant future, I offer three predictions
innovazioni, futuro
::: jessfraz

Tesla Hacker Launches Open-Source Project ‘FreedomEV’ To Run On Rooted Teslas, Bring New Wi-Fi Hotspot and Anti-Tracking Features
innovazioni, futuro
::: Slashdot

pecora

China is playing AI leapfrog
artificial intelligence
::: fabiochiusi

We always say that coders are responsible for what algorithms produce (e.g. in the AI/ethics debate, or in the quest for algorithmic transparency), and yet, for some reason, in art it’s the opposite: isn’t the coder the actual artist, here?
artificial intelligence | etica
::: fabiochiusi

Will machines take over mental health care?
#AI tools like the ones developed by spinoff @ginger_io may be an effective addition to mental health care treatment, helping connect users to clinicians and monitor their response to more traditional forms of therapy
artificial intelligence
::: medialab

Getting smart about AI
Ubuntu
::: ubuntu

Machine learning will be able to do anything you could train a dog to do
machine learning
::: FrankPasquale

New “Metallic Wood” Is As Strong As Titanium But Much Lighter
innovazioni, futuro
::: Slashdot

“We need to be cautious about embracing the new Utopianism of »decentralization«. Getting the power dynamics of our digital activities right can only happen through active interrogation of how power operates in each blockchain system” – 📄 by @angela_walch
blockchain e crypto*
::: jakublipinski

Trump has a plan to keep America first in artificial intelligence
The initiative is designed to boost America’s AI industry by reallocating funding, creating new resources, and devising ways for the country to shape the technology even as it becomes increasingly global
artificial intelligence
::: fabiochiusi ::: fabiochiusi

I am optimistic that there is still time to shift towards building ethical and inclusive #AI systems that respect our human dignity and rights
etica | artificial intelligence
::: medialab

Japan plans to begin testing flying cars later this year
::: IEEESpectrum

DzXPPeGX4AAOoa1

IBM’s AI loses to a human debater, but it’s still persuasive technology
artificial intelligence
::: fabiochiusi

Resist the robot takeover. We must not hand over important decisions to #algorithms we don’t understand. Read the opinion piece by @nicolaskb & @spielkamp in @POLITICOEurope (for the record: we didn’t come up with the headline) #ai #adm #automatingsociety
algoritmi, codice | artificial intelligence
::: algorithmwatch

Fire (and lots of it): Berkeley researcher on the only way to fix cryptocurrency
blockchain e crypto*
::: RadioProzac

In China, Some Teachers Are Using AI To Grade Homework
artificial intelligence
::: Slashdot

2019 top digital transformation tech investments
innovazioni, futuro | economia, lavoro
::: ValaAfshar

We’re actually doing this! Comparing curiosity in AI and kids
artificial intelligence
::: AlisonGopnik

Square CEO Jack Dorsey Says Bitcoin’s Lightning Is Coming To Cash App
blockchain e crypto*
::: Slashdot

“AI is not just a curiosity. It’s a technology that’s going to fundamentally change much of our daily lives.” – Tom Mitchell
artificial intelligence
::: RichRogersIoT

The first step of any effective AI strategy is to rebrand the discarded Big Data strategy you commissioned but never used a few years ago
artificial intelligence
::: evgenymorozov

slide_9_physics_cakes

So far the cryptocurrency craze has made online criminality easier, created bubbles, fleeced naive investors, imposed grotesque waste in so-called mining, offered funding for malfeasance & facilitated tax evasion. What is the social value in any of this?
blockchain e crypto*
::: FrankPasquale

The president of the United States has dialed up an executive order aimed at “accelerating our national leadership” in artificial intelligence. But the order, seen as a prompt to win an AI arms race against China, offers little in the way of details
politica | artificial intelligence
::: IEEESpectrum

After 800+ attempts to contact @MarsRovers Opportunity, today we’re announcing the end of a successful Martian mission. Intended to explore the Red Planet for 90 days, Oppy outlived its mission lifetime by 14+ years
robots
::: JimBridenstine ::: cmnit ::: TheOnion ::: BarackObama ::: starstrickenSF ::: Taraustralis ::: disinformatico

Left To Their Own Devices, Pricing Algorithms Resort To Collusion
algoritmi, codice
::: Slashdot

This robot uses celestial navigation and distance-tracking methods similar to those used by the desert ant to navigate and successfully return to its starting point
robots
::: IEEESpectrum

New AI Now research paper: “DIRTY DATA, BAD PREDICTIONS.” First study of its kind to reveal how predictive policing platforms are influenced by data gathered from illegal and discriminatory police practices
artificial intelligence | dati, raccolta | privacy, sicurezza, spionaggio, virus
::: AINowInstitute

the real legacy of these cultures isn’t ruins or artefacts. It’s ideas, values, languages and writing systems, stories, institutions, beliefs. It’s us
thread filosofico
innovazioni, futuro
::: fchollet

The #evolution of #airplanes: The evolution of the major airplane models during the 100-yr history of aviation
innovazioni, futuro
::: ulaulaman

Airbus Is Giving Up On the A380
economia, lavoro
::: Slashdot

La culture numérique est-elle le latin du 21ème siècle?
scuola, educazione
::: LorenzoTomasin

cuore

Gestire la clipboard

top4

A me nessuno dice mai niente ma indagando ontehtoobz ogni tanto trovo cose…
Come xclip, fa proprio quello che volevo da tanto tempo. A dirla tutta ne ho già parlato ma non in modo organico, cerco di rimediare.

Niente di meglio che un esempio per vedere cosa fa, con la teoria non sono tanto buono, ecco:

c0

e nella clipboard ho, vediamo con Crtl-V

prima riga
seconda
terza.

cioè l’output del comando precedente. Comodo, molto più comodo di selezionare il testo e copiarlo con Maiusc-Ctrl-C.

Tanto comodo (come si vedrà in un prossimo post (forse)) che ho creato lo script _k, abilitato e messo in ~/bin

#!/bin/bash
xclip -f -selection clipboard

Da testare:

c2

e nella clipboard ho:

3.142857142857143
3.141592653589793

Come Ctrl-V fa coppia con Ctrl-C creo _p che fa coppia di _k:

#!/bin/bash
xclip -o  -selection clipboard

lo abilito e sposto in ~/bin ed ecco:

c4

Per sapere tutto di xclip aprire questo link. Prossimamente risulterà meno oscuro come intendo utilizzare _k &co (probabilmente… forse…) 😐

Maxima – 203 – Definire funzioni – 4

Amsterdam

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.610.

Funzioni e variabili

apply (F, [x_1, ..., x_n])
Constructs and evaluates an expression F(arg_1, ..., arg_n).

apply does not attempt to distinguish array functions from ordinary functions; when F is the name of an array function, apply evaluates F(...) (that is, a function call with parentheses instead of square brackets). arrayapply evaluates a function call with square brackets in this case.

See also funmake and args.

apply evaluates its arguments. In this example, min is applied to the value of L.

(%i1) L : [1, 5, -10.2, 4, 3];
(%o1)                        [1, 5, - 10.2, 4, 3]
(%i2) apply (min, L);
(%o2)                               - 10.2

apply evaluates arguments, even if the function F quotes them.

(%i3) F (x) := x / 1729;
                                          x
(%o3)                            F(x) := ----
                                         1729
(%i4) fname : F;
(%o4)                                  F
(%i5) dispfun (F);
                                          x
(%t5)                            F(x) := ----
                                         1729

(%o5)                                [%t5]
(%i6) dispfun (fname);

fundef: no such function: fname
 -- an error. To debug this try: debugmode(true);
(%i7) apply (dispfun, [fname]);
                                          x
(%t7)                            F(x) := ----
                                         1729

(%o7)                                [%t7]

apply evaluates the function name F. Single quote ' defeats evaluation. demoivre is the name of a global variable and also a function.

(%i8) demoivre;
(%o8)                                false
(%i9) demoivre (exp (%i * x));
(%o9)                         %i sin(x) + cos(x)
(%i10) apply (demoivre, [exp (%i * x)]);

apply: found false where a function was expected.
 -- an error. To debug this try: debugmode(true);
(%i11) apply ('demoivre, [exp (%i * x)]);
(%o11)                        %i sin(x) + cos(x)

How to convert a nested list into a matrix:

(%i12) a:[[1,2],[3,4]];
(%o12)                         [[1, 2], [3, 4]]
(%i13) apply(matrix, a);
                                   [ 1  2 ]
(%o13)                             [      ]
                                   [ 3  4 ]

block ([v_1, ..., v_m], expr_1, ..., expr_n)
block (expr_1, ..., expr_n)
The function block allows to make the variables v_1, ..., v_m to be local for a sequence of commands. If these variables are already bound block saves the current values of the variables v_1, ..., v_m (if any) upon entry to the block, then unbinds the variables so that they evaluate to themselves; The local variables may be bound to arbitrary values within the block but when the block is exited the saved values are restored, and the values assigned within the block are lost.

If there is no need to define local variables then the list at the beginning of the block command may be omitted. In this case if neither return nor go are used block behaves similar to the following construct:

( expr_1, expr_2,... , expr_n );

expr_1, ..., expr_n will be evaluated in sequence and the value of the last expression will be returned. The sequence can be modified by the go, throw, and return functions. The last expression is expr_n unless return or an expression containing throw is evaluated.

The declaration local(v_1, ..., v_m) within block saves the properties associated with the symbols v_1, ..., v_m, removes any properties before evaluating other expressions, and restores any saved properties on exit from the block. Some declarations are implemented as properties of a symbol, including :=, array, dependencies, atvalue, matchdeclare, atomgrad, constant, nonscalar, assume, and some others. The effect of local is to make such declarations effective only within the block; otherwise declarations within a block are actually global declarations.

block may appear within another block. Local variables are established each time a new block is evaluated. Local variables appear to be global to any enclosed blocks. If a variable is non-local in a block, its value is the value most recently assigned by an enclosing block, if any, otherwise, it is the value of the variable in the global environment. This policy may coincide with the usual understanding of “dynamic scope”.

The value of the block is the value of the last statement or the value of the argument to the function return which may be used to exit explicitly from the block. The function go may be used to transfer control to the statement of the block that is tagged with the argument to go. To tag a statement, precede it by an atomic argument as another statement in the block. For example: block ([x], x:1, loop, x: x+1, ..., go(loop), ...). The argument to go must be the name of a tag appearing within the block. One cannot use go to transfer to a tag in a block other than the one containing the go.

Blocks typically appear on the right side of a function definition but can be used in other places as well.

See also return and go.

break (expr_1, ..., expr_n)
Evaluates and prints expr_1, ..., expr_n and then causes a Maxima break at which point the user can examine and change his environment. Upon typing exit; the computation resumes.

catch (expr_1, ..., expr_n)
Evaluates expr_1, ..., expr_n one by one; if any leads to the evaluation of an expression of the form throw (arg), then the value of the catch is the value of throw (arg), and no further expressions are evaluated. This “non-local return” thus goes through any depth of nesting to the nearest enclosing catch. If there is no catch enclosing a throw, an error message is printed.

If the evaluation of the arguments does not lead to the evaluation of any throw then the value of catch is the value of expr_n.

(%i14) lambda ([x], if x < 0 then throw(x) else f(x))$

(%i15) g(l) := catch (map (''%, l))$

(%i16) g ([1, 2, 3, 7]);
(%o16)                     [f(1), f(2), f(3), f(7)]
(%i17) g ([1, 2, -3, 7]);
(%o17)                                - 3

The function g returns a list of f of each element of l if l consists only of non-negative numbers; otherwise, g “catches” the first negative element of l and “throws” it up.

Maxima – 202 – Definire funzioni – 3

DwkZ

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.609.

macroexpand1 (expr)
Returns the macro expansion of expr without evaluating it, when expr is a macro function call. Otherwise, macroexpand1 returns expr.

macroexpand1 quotes its argument. However, if the expansion of a macro function call has side effects, those side effects are executed.

If the expansion of expr yields another macro function call, that macro function call is not expanded.

See also ::=, macros, and macroexpand.

(%i1) g (x) ::= x / 99;
                                           x
(%o1)                             g(x) ::= --
                                           99
(%i2) h (x) ::= buildq ([x], g (x - a));
(%o2)                   h(x) ::= buildq([x], g(x - a))
(%i3) a: 1234;
(%o3)                                1234
(%i4) macroexpand1 (h (y));
(%o4)                              g(y - a)
(%i5) h (y);
                                   y - 1234
(%o5)                              --------
                                      99

Differenza rispetto macroexpand: solo in %o4.

macros
Default value: [].

macros is the list of user-defined macro functions. The macro function definition operator ::= puts a new macro function onto this list, and kill, remove, and remfunction remove macro functions from the list.

See also infolists.

splice (a)
Splices (interpolates) the list named by the atom a into an expression, but only if splice appears within buildq; otherwise, splice is treated as an undefined function. If appearing within buildq as a alone (without splice), a is substituted (not interpolated) as a list into the result. The argument of splice can only be an atom; it cannot be a literal list or an expression which yields a list.

Typically splice supplies the arguments for a function or operator. For a function f, the expression f (splice (a)) within buildq expands to f (a[1], a[2], a[3], ...). For an operator o, the expression "o" (splice (a)) within buildq expands to "o" (a[1], a[2], a[3], ...), where o may be any type of operator (typically one which takes multiple arguments). Note that the operator must be enclosed in double quotes ".

(%i6) buildq ([x: [1, %pi, z - y]], foo (splice (x)) / length (x));
                              foo(1, %pi, z - y)
(%o6)                       -----------------------
                            length([1, %pi, z - y])
(%i7) buildq ([x: [1, %pi]], "/" (splice (x)));
                                       1
(%o7)                                 ---
                                      %pi
(%i8) matchfix ("<>", "<>");
(%o8)                                 <>
(%i9) buildq ([x: [1, %pi, z - y]], "<>" (splice (x)));
(%o9)                          <>1, %pi, z - y<>

cit. & loll – 135

cit. e il loll – rassegna costi e benefici 😋

000DzMWmgoWwAAWtH6

This didn’t age well…
::: LeapingRobot

“Corso Base di Linux con Bob”. Il “con Bob” è parte integrante del titolo
Bob Roberto rockz! 💥
::: madbob

Bedtime Stories
::: turnoff_us

Per me, ginecologo, è pur sempre qualcosa di unico ed emozionante
::: MedBunker

I’m happy to affirm this as well. The well-funded vulture capitalists have as much moral authority on this as they do about anything else: none
::: wwahammy

OH: Single instruction
::: samth

Huawei is bad because it
::: evgenymorozov

Not a slam on this person or JS progs, they’re trying to do their best in a horrible context
non verificato (mi manca il coraggio)
::: Symbo1ics

See also: chess in the 1980s
::: lizardbill

If you ever feel like a failure, just remember that
::: matthew_d_green

Designing the system and writing the code is the easy part
::: fchollet

DytUPFeUYAEWbwb

The apocalypse will come and go and I
::: extremefriday

Sì certo, le curve delle donne, ma allora io le potrei dire, anche con il rispetto per l’autorità, che anche soltanto le due cose come CURVE DI LISSAJOUS, capisce?
::: Arnathoth

You know you are a nerd when you spend your vacation
::: jessfraz

Era finito il toner 🐈
::: Tony_Matique

Difference between machine learning and AI
::: gadievron

I programmatori lavorano di notte
::: madbob

When can you do it?
::: RichRogersIoT

No Hard Feelings
::: jessfraz

have a few questions
::: johnregehr

DzG7C6PWwAMY3hy

‘Fly, My Pretties,’ Says Jeff Bezos Releasing Swarm Of Amazon Drones To Hunt Down Nude Photos
the Onion, nèh!
::: slashdot

Heisenberg Release Uncertainty Principle
::: RichRogersIoT

Il marketing #Apple è quella roba che nel 2019
::: Genjuro75

Too many programmers program this way, and that’s why most software is the way it is
::: keithtpinson

The moment you realize “it’s totally okay to just let people be wrong on the internet” is the moment twitter instantly ceases to cause you stress
::: Viss

Internet dopo le 19:00 è chiuso
::: LSpark_zwz

Non voglio sottovalutare i vantaggi del 5G, ma se
::: ivosilvestro

Undefined
::: hrmny_

This made me remember when I used to make the calculator say “boobs” “80085” and “hello” 😛
::: jessfraz

sfollati

Coding as a team
::: jessfraz

My mom 50 years ago with an IBM 1401 and me just now with a DEC PDP-10
::: kclemson

This is my aesthetic
::: jessfraz

Nevertheless, she persisted
::: timetit

A sad decline for a once-proud operating system
::: waldojaquith

#GDPR #privacy #privacylaw #privacypolicy
::: saurnou

Hofstadter’s Law
::: RichRogersIoT

Tip of the day: If your printer has a USB port
::: mikko_2014

Local Gas Station
::: gknauth

No way to prevent this
::: mjg59

sashay

Maxima – 201 – Definire funzioni – 2

top2

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.606.

Macros

buildq (L, expr)
Substitutes variables named by the list L into the expression expr, in parallel, without evaluating expr. The resulting expression is simplified, but not evaluated, after buildq carries out the substitution.

The elements of L are symbols or assignment expressions symbol: value, evaluated in parallel. That is, the binding of a variable on the right-hand side of an assignment is the binding of that variable in the context from which buildq was called, not the binding of that variable in the variable list L. If some variable in L is not given an explicit assignment, its binding in buildq is the same as in the context from which buildq was called.

Then the variables named by L are substituted into expr in parallel. That is, the substitution for every variable is determined before any substitution is made, so the substitution for one variable has no effect on any other.

If any variable x appears as splice (x) in expr, then x must be bound to a list, and the list is spliced (interpolated) into expr instead of substituted.

Any variables in expr not appearing in L are carried into the result verbatim, even if they have bindings in the context from which buildq was called.

a is explicitly bound to x, while b has the same binding (namely 29) as in the calling context, and c is carried through verbatim. The resulting expression is not evaluated until the explicit evaluation ''%.

(%i1) (a: 17, b: 29, c: 1729)$

(%i2) buildq ([a: x, b], a + b + c);
(%o2)                             x + c + 29
(%i3) ''%;
(%o3)                              x + 1758

e is bound to a list, which appears as such in the arguments of foo, and interpolated into the arguments of bar.

(%i1) buildq ([e: [a, b, c]], foo (x, e, y));
(%o1)                        foo(x, [a, b, c], y)
(%i2) buildq ([e: [a, b, c]], 2 * splice (e));
(%o2)                               2 a b c

The result is simplified after substitution. If simplification were applied before substitution, these two results would be the same.

(%i1) buildq ([e: [a, b, c]], splice (e) + splice (e));
(%o1)                           2 c + 2 b + 2 a
(%i2) buildq ([e: [a, b, c]], 2 * splice (e));
(%o2)                               2 a b c

The variables in L are bound in parallel; if bound sequentially, the first result would be foo (b, b). Substitutions are carried out in parallel; compare the second result with the result of subst, which carries out substitutions sequentially.

(%i1) buildq ([a: b, b: a], foo (a, b));
(%o1)                              foo(b, a)
(%i2) buildq ([u: v, v: w, w: x, x: y, y: z, z: u],
              bar (u, v, w, x, y, z));
(%o2)                        bar(v, w, x, y, z, u)
(%i3) subst ([u=v, v=w, w=x, x=y, y=z, z=u],
             bar (u, v, w, x, y, z));
(%o3)                        bar(u, u, u, u, u, u)

Construct a list of equations with some variables or expressions on the left-hand side and their values on the right-hand side. macroexpand shows the expression returned by show_values.

(%i1) show_values ([L]) ::= buildq ([L], map ("=", 'L, L));
(%o1)          show_values([L]) ::= buildq([L], map("=", 'L, L))
(%i2) (a: 17, b: 29, c: 1729)$

(%i3) show_values (a, b, c - a - b);
(%o3)                 [a = 17, b = 29, c - b - a = 1683]
(%i4) macroexpand (show_values (a, b, c - a - b));
(%o4)           map(=, '([a, b, c - b - a]), [a, b, c - b - a])

Given a function of several arguments, create another function for which some of the arguments are fixed.

(%i1) curry (f, [a]) :=
             buildq ([f, a], lambda ([[x]], apply (f, append (a, x))))$

(%i2) by3 : curry ("*", 3);
(%o2)               lambda([[x]], apply(*, append([3], x)))
(%i3) by3 (a + b);
(%o3)                              3 (b + a)

macroexpand (expr)
Returns the macro expansion of expr without evaluating it, when expr is a macro function call. Otherwise, macroexpand returns expr.

If the expansion of expr yields another >macro function call, that macro function call is also expanded.

macroexpand quotes its argument. However, if the expansion of a macro function call has side effects, those side effects are executed.

See also ::=, macros, and macroexpand1.

(%i1) g (x) ::= x / 99;
                                           x
(%o1)                             g(x) ::= --
                                           99
(%i2) h (x) ::= buildq ([x], g (x - a));
(%o2)                   h(x) ::= buildq([x], g(x - a))
(%i3) a: 1234;
(%o3)                                1234
(%i4) macroexpand (h (y));
                                     y - a
(%o4)                                -----
                                      99
(%i5) h (y);
                                   y - 1234
(%o5)                              --------
                                      99

Sicurezza e disinformazione – 11

Sono sicuri i nostri ‘puters? No. Sono vere tutte quelle che sentiamo? No! Intanto ecco qua la mia rassegna.

000Dy5LwriXcAA19H5

Fascinating story in @BW about how @Huawei appears to have tried to steal technology from a small U.S. company
ovviamente da verificare
ditte
::: waltmossberg

Come per il sito di Calenda, anche quello del Reddito di Cittadinanza del Governo ha qualche problemino con la Privacy
privacy, sicurezza, spionaggio, virus
::: DavidPuente ::: AndreaBertaglio

If misinformation “has become an epidemic the leading cause is news organizations”
disinformazione, fake news, bufale
::: marklittlenews

Su Open, in esclusiva con il CNR di Pisa, pubblico una prima analisi dei followers degli account politici. Iniziamo con Matteo Salvini, Luigi Di Maio e Matteo Renzi
disinformazione, fake news, bufale | politica
::: DavidPuente

Article 13 is back on – and it got worse, not better
censura
::: jeffjarvis ::: paul_keller ::: doctorow ::: communia_eu ::: Senficon ::: direitosdig ::: communia_eu ::: BrusselsGeek ::: Slashdot ::: communia_eu ::: Senficon ::: Senficon ::: denschub ::: communia_eu ::: communia_eu ::: communia_eu ::: glynmoody ::: communia_eu

jfc this kids smartwatch was loaded with tracking tech, had like zero data protection, and the app to control it belongs to some random Chinese company with no privacy policy
privacy, sicurezza, spionaggio, virus
::: CraigSilverman

Tech firms could be slapped with EU fines as high as 4% of revenue if they fail to remove terror propaganda quickly enough
privacy, sicurezza, spionaggio, virus
::: guidoromeo

Zcash Discloses Vulnerability That Could Have Allowed ‘Infinite Counterfeit’ Cryptocurrency
frodi
::: zcashco

Chrome Can Tell You if Your Passwords Have Been Compromised
privacy, sicurezza, spionaggio, virus
::: Slashdot

How to Protect Your Privacy on Linux
privacy, sicurezza, spionaggio, virus
::: UnixToolTip

Software Executive Exploits ATM Loophole To Steal $1 Million
frodi
::: Slashdot

Cosa cambia con la #VoiceSearch e perché è bene che chi produce contenuti cominci a preoccuparsi
privacy, sicurezza, spionaggio, virus
::: SergioGridelli

EDVAC

EDVAC

Ecco la seconda puntata dello studio svolto dal CNR di Pisa per Open. Oggi tocca ai followers di Laura Boldrini, Alessandro Di Battista e Giorgia Meloni
disinformazione, fake news, bufale
::: DavidPuente

China Hacked Norway’s Visma To Steal Client Secrets, Investigators Say
privacy, sicurezza, spionaggio, virus
::: Slashdot

A Flaw Found in E-Ticketing Systems Used By at Least Eight Airlines Could Be Exploited To Access Sensitive Information About Travelers
privacy, sicurezza, spionaggio, virus
::: Slashdot

Researcher Reveals a Severe, Unpatched Mac Password Flaw To Protest Apple Bug Bounty
privacy, sicurezza, spionaggio, virus
::: Slashdot

10x more than a typical month’s worth of traffic. I just blocked the single IP involved
privacy, sicurezza, spionaggio, virus
::: quicklisp

WhatsApp on How It’s Fighting Bulk Messaging and Suspicious Accounts
privacy, sicurezza, spionaggio, virus
::: Slashdot

Security researchers have discovered a remote code execution vulnerability in LibreOffice, @softpedianews reports. Evidently “the flaw can be exploited with just a malicious ODT document that includes code for running a macro with a mouse-hover action”
privacy, sicurezza, spionaggio, virus
::: linuxjournal

Scoop: documents show AT&T, T-Mobile, Sprint customer location data sold to around ~250~ bounty hunters and related businesses. Some hunters tracked phones tens of thousands of times. Also sold GPS data reserved for 911 calls; unprecedented. Massive scale
frodi
::: josephfcox

Holy shit this is an amazing set of knowledge
Awesome Firmware Security & Other Helpful Documents
privacy, sicurezza, spionaggio, virus
::: jessfraz

Facebook Will Reveal Who Uploaded Your Contact Info For Ad Targeting
ad, pubblicità
::: Slashdot

Google’s Adiantum is a length-preserving encryption composition suitable for disk encryption on ARM and non-x86 architectures. It’s now in Linux 5.0
privacy, sicurezza, spionaggio, virus
::: sweis

leobear

Huawei Admits To Needing 5 Years, $2 Billion To Fix Security Issues
privacy, sicurezza, spionaggio, virus
::: Slashdot

Many Popular iPhone Apps Secretly Record Your Screen Without Asking
privacy, sicurezza, spionaggio, virus
::: Slashdot

#CambridgeAnalytica Fact-finding over, Italian SA ready to impose sanctions on #Facebook. Data relating to Italian nationals were processed unlawfully because no appropriate information had been given and no specific consent obtained
frodi | Facebook
::: meobaldo ::: fabiochiusi

Three out of the four vulnerabilities in the latest iOS advisory were exploited in the wild, yikes
privacy, sicurezza, spionaggio, virus
::: taviso

Spotify Bans Ad Blockers In Updated ToS
ad, pubblicità
::: Slashdot

Linux: eBPF Spectre v1 mitigation is insufficient
bug
::: ProjectZeroBugs

Le patate danneggiano il cervello di bambini e adolescenti, lo dice la scienza?
disinformazione, fake news, bufale | dati, raccolta
::: RadioProzac

Perché chi crede a una bufala poi crede a tutte? Le bufale sono magnetiche e se non si ha la capacità di distinguerle si entra in un tunnel
disinformazione, fake news, bufale
::: MedBunker

In a nutshell: domestic politicians who make+repeat misleading statements are more pervasive part of wider disinformation problems than foreign state-backed media+bot/troll operations (troubling as these are)
disinformazione, fake news, bufale
::: rasmus_kleis

Don’t copy-paste from a website to a terminal
privacy, sicurezza, spionaggio, virus
::: UnixToolTip

From Stamos: “There are twenty Cambridge Analyticas that still exist, they’re just not dumb enough to steal data from Facebook. They legally buy it from Equifax and Transunion and Acxiom, and Facebook and Google allow them to then hypertarget ads”
privacy, sicurezza, spionaggio, virus
::: mathewi

51413148_10205519180816794_9024176500252868608_n

Twitter Still Can’t Keep Up With Its Flood of Junk Accounts, Study Finds
Twitter | disinformazione, fake news, bufale
::: Slashdot

Android security vulnerability: attackers get access to your phone if you open a .png file
privacy, sicurezza, spionaggio, virus
::: linuxjournal

Please Stop Using Internet Explorer, Microsoft Says
privacy, sicurezza, spionaggio, virus
::: Slashdot

Why Data, Not Privacy, Is the Real Danger
dati, raccolta | privacy, sicurezza, spionaggio, virus
::: Slashdot

The Jeff Bezos affair has led to this surprisingly good explainer about how to protect your data and prevent a situation where *you* have to accuse the National Enquirer of extortion
privacy, sicurezza, spionaggio, virus
::: jeanqasaur ::: jeanqasaur

YouTube announced they will stop recommending some conspiracy theories such as flat earth. I worked on the AI that promoted them by the *billions*
social media | disinformazione, fake news, bufale
::: gchaslot ::: ProfaDavis

Google, the company who’s motto is “don’t be evil” does a deal with Russian government to ban websites that Putin doesn’t like, including anti corruption exposes, from its searches. That seems pretty evil to me
censura
::: Billbrowder

Google Play Caught Hosting An App That Steals Users’ Cryptocurrency
privacy, sicurezza, spionaggio, virus
::: Slashdot

Giusto chiedersi, con serietà e il maggior rigore possibile, l’impatto delle bugie create ad arte da propagandisti, bot, troll etc. sui social. Senza dimenticare che l’uomo più potente del mondo non fa che delegittimare il giornalismo in quanto tale — fact-checking incluso
disinformazione, fake news, bufale
::: fabiochiusi

Absolutely valid concerns raised here, @facebook should be listening to @mozilla and other signatories
privacy, sicurezza, spionaggio, virus
::: fabiochiusi

Russia To Disconnect From the Internet as Part of a Planned Test
Web, Internet
::: Slashdot

Lissajous

La precisione e la realtà

s-p

Ogni tanto qualcuno riporta una variante di come il ‘puter sbaglia clamorosamente su cose semplicissimissime. Per esempio ecco Vanessa (rockz! 💥, vorei essere come lei (anche se non sono invidioso per natura, nèh!)): […] the people that make fun of JS for 0.1 + 0.2 ≠ 0.3.

Uh! a me fa venire in mente due cose. Comincio con la verifica

$ python3 -q
>>> 0.1 + 0.2
0.30000000000000004
>>>
$ node
> 0.1 + 0.2
0.30000000000000004
$ racket
Welcome to Racket v6.11.
> (+ 0.1 0.2)
0.30000000000000004
> ;; ma anche
  (+ 1/10 2/10)
3/10
> ;; e
  (exact->inexact (+ 1/10 2/10))
0.3
$ echo "0.1 + 0.2" | bc
.3
$ calc 0.1 + 0.2
	0.3
$ maxima -q
(%i1) 0.1 + 0.2;
(%o1)                                 0.3

OK, Racket rockz! 💥, come già si sapeva. Ma gli interpretati dinamicamente come JavaScript, Python e altri ancora, da me non usati correntemente, fanno proprio come dice Vanessa (et al.).

Non è solo una stravaganza della REPL, è davvero vero:

$ python3 -q
>>> (0.1 + 0.2) == 0.3
False
>>> round((0.1 + 0.2), 3) == 0.3
True

Non è una cosa nuova, anzi –qui entro nel c’era una volta– io che sono vecchio ricordo che fin da quando ho cominciato c’erano due funzioni (nostre, cioè fatte da uno di noi o prese da qualche guru nostrano (o anche no)): LEQR e LEQD, rispettivamente per argomenti REAL (4 bytes) e DOUBLE PRECISION (8 bytes); da dichiarare LOGICAL. Con Python diventano una sola, qeq (sta per quasi-equal):

def qeq(a, b):
    return abs(a - b) < 1e-15

Da provare:

$ py3
>>> def qeq(a, b):
...     return abs(a - b) < 1e-15 
... 
>>> qeq(0.1 + 0.2, 0.3)
True
>>> from math import pi
>>> qeq(22/7, pi)
False
>>> #difatti
>>> 22/7 - pi
0.0012644892673496777

Ma se devo dire tutta la verità questa funzione (nelle due varianti) non veniva usata: era lunga una sola riga quindi niente risparmio di battute per contro l’uso comportava un carico maggiore per il sistema, la chiamata a funzione. Volendo potrei raccontare dello statement function, ecco l’inizio di pag. 7-7 del manuale del Fortran IV di Pr1me:

st-fun

Anch’io so cose lollose come Vanessa, solo di utilità assolutamente nulla (oggi, come passa il tempo!).

H/T a AP che mi ha corretto la bozza. E i suggerimenti.

Maxima – 200 – Definire funzioni – 1

indri

Continuo da qui, copio dal Reference Manual, PDF scaricabile da qui, sono a p.605.

Funzioni ordinarie

To define a function in Maxima you use the := operator. E.g.

f(x) := sin(x)

defines a function f. Anonymous functions may also be created using lambda. For example lambda ([i, j], ...) can be used instead of f where

f(i,j) := block ([], ...);
map (lambda ([i], i+1), l)

would return a list with 1 added to each term.

You may also define a function with a variable number of arguments, by having a final argument which is assigned to a list of the extra arguments:

(%i1) f ([u]) := u;
(%o1)                             f([u]) := u
(%i2) f (1, 2, 3, 4);
(%o2)                            [1, 2, 3, 4]
(%i3) f (a, b, [u]) := [a, b, u];
(%o3)                      f(a, b, [u]) := [a, b, u]
(%i4) f (1, 2, 3, 4, 5, 6);
(%o4)                        [1, 2, [3, 4, 5, 6]]

The right hand side of a function is an expression. Thus if you want a sequence of expressions, you do

f(x) := (expr1, expr2, ..., exprn);

and the value of exprn is what is returned by the function.

If you wish to make a return from some expression inside the function then you must use block and return:

block ([], expr1, ..., if (a > 10) then return(a), ..., exprn)

is itself an expression, and so could take the place of the right hand side of a function definition. Here it may happen that the return happens earlier than the last expression.

The first [] in the block, may contain a list of variables and variable assignments, such as [a: 3, b, c: []], which would cause the three variables a, b, and c to not refer to their global values, but rather have these special values for as long as the code executes inside the block, or inside functions called from inside the block. This is called dynamic binding, since the variables last from the start of the block to the time it exits. Once you return from the block, or throw out of it, the old values (if any) of the variables will be restored.

It is certainly a good idea to protect your variables in this way. Note that the assignments in the block variables, are done in parallel. This means, that if you had used c: a in the above, the value of c would have been the value of a at the time you just entered the block, but before a was bound. Thus doing something like

block ([a: a], expr1, ... a: a+3, ..., exprn)

will protect the external value of a from being altered, but would let you access what that value was. Thus the right hand side of the assignments, is evaluated in the entering context, before any binding occurs. Using just block ([x], ...) would cause the x to have itself as value, just as if it would have if you entered a fresh Maxima session.

The actual arguments to a function are treated in exactly same way as the variables in a block. Thus in

f(x) := (expr1, ..., exprn);

and

f(1);

we would have a similar context for evaluation of the expressions as if we had done block ([x: 1], expr1, ..., exprn).

Inside functions, when the right hand side of a definition, may be computed at runtime, it is useful to use define and possibly buildq.

Funzioni array

An array function stores the function value the first time it is called with a given argument, and returns the stored value, without recomputing it, when that same argument is given.

Such a function is often called a memoizing function.

Array function names are appended to the global list arrays (not the global list functions). arrayinfo returns the list of arguments for which there are stored values, and listarray returns the stored values. dispfun and fundef return the array function definition.

arraymake constructs an array function call, analogous to funmake for ordinary functions. arrayapply applies an array function to its arguments, analogous to apply for ordinary functions. There is nothing exactly analogous to map for array functions, although map(lambda([x], a[x]), L) or makelist(a[x], x, L), where L is a list, are not too far off the mark.

remarray removes an array function definition (including any stored function values), analogous to remfunction for ordinary functions.

kill(a[x]) removes the value of the array function a stored for the argument x; the next time a is called with argument x, the function value is recomputed. However, there is no way to remove all of the stored values at once, except for kill(a) or remarray(a), which also remove the function definition.