text:
If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

## Pre-algebra

### Course: Pre-algebra>Unit 9

Lesson 6: Writing & solving proportions

# Worked example: Solving proportions

Learn the reasoning behind solving proportions. We'll put some algebra to work to get our answers, too. Created by Sal Khan and Monterey Institute for Technology and Education.

## Want to join the conversation?

• In the first example on how to find the proportion, Sal said to multiply 8x10/8 to get 10. He said he made the calculation on his head, but I wonder what steps should I follow to get that answer? The 10/8 looks obvious after he gave it away but if he hadn't I don't think I could have find it on my own. At least I don't know how to do it at the moment.
(76 votes)
• Well, let's see...we're basically asking 8 times what = 10, right? So, in algebra terms, 8 x n = 10 or 8n = 10. Divide both sides by 8 to get the n by itself and you get n = 10/8. Does that make sense?
(68 votes)
• Is there any easier way to do it? Like a way without using common core? Because this is way to confusing!
(33 votes)
• In that first example that Sal gave you, try checking for fractions to simplify first. You can see that the first fraction `8/36` simplifies to `2/9`.
``2       10--  =   --9        n``

Now, we need to ask ourselves this question: "2 times what equals 10?" And to answer that question, 2 times 5 equals 10. So, we now know to multiply 5 on the denominator of the first fraction to find n. 9 times 5 equals 45, so `n = 45`.

There is another way: it's to cross-multiply and then solve the equation. But you won't learn about solving equations until much later in Pre-Algebra: https://www.khanacademy.org/math/pre-algebra/pre-algebra-equations-expressions/pre-algebra-intro-equations/v/variables-expressions-and-equations

Let's use Sal's example again:
``2       10--  =   --9        n``

Try drawing an 'X' with your fingers on the proportion above. That's how we'll cross-multiply it. The equation will ultimately look like this: `2 ⋅ n = 10 ⋅ 9`. Simplify the equation and you get: `2n = 90`. To solve it, you just divide 2 on both sides:
``2n = 90÷2 = ÷2n = 45``

I hope this helped!
(74 votes)
• Did anyone else hear breathing in between while he was talking? :(
(19 votes)
• i did :( i was genuinely worried but then i realised its probably because he's the one narrating almost every khan academy video so i do think its a case of tired-of-talking
(13 votes)
• i don't even know what he said during those whole 7 minutes
(19 votes)
• same :/ normally all his videos help me but this one kinda was a lil you know confusing. to help tho i'd just use the community's help and look at the comments :)
(12 votes)
• Is there anytime the answer is 0?
(14 votes)
• maby if you had 0/0 = y/0
(2 votes)
• I was doing the "Solving Proportions" and the question was like "12/7 = k/8", and whatever I did I kept getting 13.7142857143, but it was wrong. I don't understand.
(8 votes)
• Your answer is technically correct, but I think they want you to leave it as a fraction (96/7) or a mixed number (13 5/7)
(10 votes)
• Err... Did Sal show 5 different ways of solving one problem?
(7 votes)
• Yes he told many ways and some of them were confusing. The simplest way I think is Cross multiplication. Here's how to do it.

Lets take a number 3/12=4/X

1. First cross multiply the digits i.e, multiply 12 x 4 and 3 x X
2. 12 x 4 = 48 and 3 x X = 3X
3.Next, According to question 3/12=4/X so, 48 will be equal to 3X
4.48=3X
5. Now I need to find the value for X So in order to isolate X I need to divide 3X by 3 (In order to find the value for X)
6. 48= [4X/3] If I divide one side by 3 then I must also divide the other side by 3 (That is the rule of the Equation).
So, we get [48/3]=[3X/3]
7. Next lets solve it 48/3 is 16 and 3X/3 is X
8. Now we get 16=X
9. Finally, the X value is 16
10. So X=16

Hope this helps. Feel free to Comment me if you have any questions :)
(6 votes)
• The video is a bit confusing, and I'm struggling to transfer this to solving the questions for "Solving Proportions". For example in the question:

4/z = 12/5
I understand that you begin by multiplying by z.
z * 4/z = 12/5*z
--> 4 = 12/5*z

After this, the solution set asks you to multiply both sides by 5/12, the opposite fraction of the right side. Why is that?
And how does multiplying a fraction with its opposite give you one?
(6 votes)
• This concept is based upon the Inverse Property of Multiplication that says:
Any number multiplied by its reciprocal = 1
For example: 12/5 * 5/12 = 60/60 = 1

If you find it easier, you can do cross multiplication. This is where you multiply along each diagonal of the proportion.
4/z = 12/5
12(z) = 4(5)
12z = 20
Then, divide by 12: z = 20/12 = 5/3

Hope this helps.
(10 votes)
• i am pretty confused on how to solve problems like 7/3 = 4/t
PLEASE HELP!
(7 votes)
• All you have to do is cross multiply.
7/3 * 4/t = 12/7t
12/7=1 1/3
(3 votes)
• I'm going to ask for clarification of my understanding of Sal's method at . I believe I understand how it works, but it actually greatly confused me, so maybe someone else reading this can get something from it.

What confused me is that while it makes sense that 8 * 10 / 8 = 10 because that's how the reciprocal works, I didn't get why 36 * 8 / 10 gave the correct answer.

Thinking over it, I'm pretty sure this only works because if 10/8 raises 8 to 10, it follows that multiplying the denominator by that same fraction would give you a proportional increase that is the same as 8 -> 10. IE, you're increasing both numbers, 8 and 36, by the same multiplier. It would be the same as multiplying both numbers by 2, or 3. You'd still have a proportional fraction after multiplying, as long as both numbers are multiplied by the same value.

And obviously, choosing the multiplier to use, it makes sense to go with the multiplier which raises 8 to 10, because raising 36 by that multiplier reveals what number n must be. This makes sense to me now, but initially it was incredibly confusing (I kept thinking it should have been 36 * n / 36).

GL to anyone else as confused by this as I was/am.
(9 votes)

## Video transcript

We're asked to solve the proportion. We have 8 36ths is equal to 10 over what. Or the ratio of 8/36 is equal to the ratio of 10 to what. And there's a bunch of different ways to solve this. And I'll explore really all of them, or a good selection of them. So one way to think about it is, these two need to be equivalent ratios, or really, equivalent fractions. So whatever happened to the numerator also has to happen to the denominator. So what do we have to multiply 8 by to get 10? Well you could multiply 8 times 10/8. It will definitely give you 10. So we're multiplying by 10/8 over here. Or another way to write 10/8, 10/8 is the same thing as 5/4. So we're multiplying by 5/4 to get to 10, from 8 to 10. Well, if we did that to the numerator, in order to have an equivalent fraction, you have to do the same thing to the denominator. You have to multiply it. You have to multiply it times 5/4. And so we could say this n, this thing that we just solved for, this n is going to be equal to 36 times 5 divided by 4. Or you could say that this is going to be equal to 36 times 5 divided by 4. And now, 36 divided by 4, we know what that is. We could divide both the numerator and the denominator by 4. You divide the numerator by 4, you get 9. Divide the denominator by 4 you get 1. You get 45. So that's one way to think about it. 8/36 is equal to 10/45. Another way to think about it is, what do we have to multiply 8 by to get its denominator. How much larger is the denominator 36 than 8? Well let's just divide 36/8. So 36/8 is the same thing as-- so we can simplify, dividing the numerator and the denominator by 4. That's the greatest common divisor. That's the same thing as 9/2. So if you multiply the numerator by 9/2, you get the denominator. So we're multiplying by 9/2 to get the denominator over here. Well, then we have to do the same thing over here. If 36 is 9/2 times 8, let me write this. 8 times 9/2 is equal to 36. Right? That's how we go from the numerator to the denominator. Then to figure out what the denominator here is, if we want the same fraction, we have to multiply by 9/2 again. So then we'll get 10 times 9/2 is going to be equal to n, is going to be equal to this denominator. And so this is the same thing as saying 10 times 9/2. Divide the numerator and the denominator by 2, you get 5/1, which is 45. So 45 is equal to n. Once again, we got the same way, completely legitimate way, to solve it. Now sometimes when you see proportion like this, sometimes people say, oh you can cross-multiply. And you can cross-multiply. And I'll teach you how to do that. And that's sometimes a quick way to do it. But I don't like teaching it the first time you look at proportions, because it's really just something mechanical. You really don't understand what you're doing. And it really comes out of a little bit of algebra. And I'll show you the algebra as well. But if you don't understand it, or if it doesn't make as much sense to you at this point, don't worry too much about it. So we have 8/36 is equal to 10/n. When you cross-multiply, you're saying that the numerator here, times the denominator over here, is going to be equal to, so 8 times n, is going to be equal to the denominator over here, let me just different color, the denominator over here, times the numerator over here. This is what it means to cross-multiply. So this is going to be equal to 36 times 10. Let me do this in a neutral color now. You could say that 8n is equal to 360. And so you're saying 8 times what is equal to 360. Or to figure out what that times what is, you divide 360 divided by 8. So we could divide, and this is a little bit of algebra here, we're dividing both sides of the equation by 8. And we're getting n is equal to 360 divided by 8. You could do that without thinking in strict algebraic terms. You could say 8 times what is 360. Well 8 times 360/8. If I write 8 times question mark is equal to 360, well, question mark could definitely be 360/8. If I multiply these out, this guy and that guy cancel out, and it's definitely 360. And that's why it's 360/8. But now we want to actually divide this to actually get our right answer, or a simplified answer. 8 goes into 360, 8 goes into 36 4 times, 4 times 8 is 32. You have a remainder of 4. Bring down the 0. 8 goes into 40 5 times. 5 times 8 is 40. And then you have no remainder. And you're done. Once again, we got n is equal to 45. Now the last thing I'm going to show you involves a little bit of algebra. If any of the ways before this worked, that's fine. And where this is sitting in the playlist, you're not expected to know the algebra. But I want to show you the algebra just because I wanted to show you that this cross-multiplication isn't some magic, that using algebra, we will get this exact same thing. But you could stop watching this, if you'll find this part confusing. So let's rewrite our proportion, 8/36 is equal to 10/n. And we want to solve for n. Well the easiest way to solve for n is maybe multiply both-- this thing on the left is equal to this thing on the right. So we can multiply them both by the same thing. And the equality will still hold. So we could multiply both of them by n. On the right-hand side, the n's cancel out. On the left-hand side, we have 8/36 times n is equal to 10. Now if we want to solve for n, we could literally multiply. If we want just an n here, we would want to multiply this side times 36-- I'll do that in a different color-- we'd want to multiply this side times 36 times 8, because if you multiply these guys out, you get 1. And you just have an n. But since we're doing it to the left-hand side, we also have to do it to the right-hand side, so times 36/8. These guys cancel out and we're left with n is equal to 10 times 36 is 360/8. And notice, we're getting the exact same value that we got with cross-multiplying. And with cross-multiplying, you're actually doing two steps. Actually, you're doing an extra step here. You're multiplying both sides by n, so that you had your 8n. And then you're multiplying both sides by 36, so that you get your 36 on both sides. And you get this value here. But at the end, when you simplify it, you'll get the exact same answer. So those are all different ways to solve this proportion. Probably the most obvious way, or the easiest way to do it in your head, was either just looking at what you have to multiply the numerator by and then doing the same thing to the denominator, or maybe by cross-multiplication.


text:
# Drawing with TeX

There are many packages to do pictures in (La)TeX itself (rather than importing graphics created externally), ranging from simple use of LaTeX `picture` environment, through enhancements like `eepic`, to sophisticated (but slow) drawing with PicTeX. Depending on your type of drawing, and setup, here are a few systems you may consider:

- The `picture` environment provides rather primitive

```  drawing capabilities (anything requiring more than linear
calculations is excluded, unless a font can come to your help).  The
environment's tedious insistence on its own ''\unitlength'', as the
basic measurement in a diagram, may be avoided by use of the
[[ctanpkg>picture|picture]] package, which detects whether a length is quoted
as a number or as a length, and acts accordingly.```

- epic was designed to make use of the LaTeX

```  ''picture'' environment somewhat less agonising;
[[ctanpkg>eepic|eepic]] extends it, and is capable of using ''tpic''
''\special'' commands to improve printing performance.  (If the
''\special''s aren't available, the [[ctanpkg>eepic|eepicemu]] will do the

- pict2e; this was advertised in

```  [[FAQ-latex-books|the LaTeX manual]], but didn't appear for nearly
ten years after publication of the book!  It removes all the petty
restrictions that surround the use of the ''picture''
environment.  It therefore suffers //only// from the rather
eccentric drawing language of the environment, and is a far more
useful tool than the original environment has ever been.  (Note that
[[ctanpkg>pict2e|pict2e]] supersedes David Carlisle's stop-gap
[[ctanpkg>pspicture|pspicture]].)```

- PicTeX is a venerable, and very powerful, system, that draws

```  by placing dots on the page to give the effect of a line or curve.  While
this has the potential of great power, it is (of course) much slower
than any of the other established packages.  What's more, there
are problems with its [[FAQ-docpictex|documentation]].```

```  PostScript via a set of TeX macros, which talk to PostScript using
[[FAQ-specials|''\special'' commands]].  Since PostScript is itself a
pretty powerful programming language, many astounding things can in
principle be achieved using [[ctanpkg>PSTricks|PSTricks]] (a wide range of
contributed packages, ranging from world mapping to lens design
diagrams, is available).
[[ctanpkg>Pstricks|Pstricks]]' ''\special''s are
by default specific to ''dvips'', but there is
a [[ctanpkg>Pstricks|Pstricks]] "driver" that allow [[ctanpkg>Pstricks|Pstricks]] to
operate under XeTeX.  pdfTeX users may use [[ctanpkg>pst-pdf|pst-pdf]],
which (like [[ctanpkg>epstopdf|epstopdf]] --- see
[[FAQ-pdftexgraphics|pdfLaTeX graphics]]) generates
PDF files using an auxiliary program, from [[ctanpkg>PSTricks|PSTricks]]
commands ([[ctanpkg>pst-pdf|pst-pdf]] also requires a recent installation of
the [[ctanpkg>preview|preview]] package).```
```  There is a [[ctanpkg>PSTricks|PSTricks]] mailing list
(pstricks@tug.org) which you may
[[https://tug.org/mailman/listinfo/pstricks|join]], or you may
just browse the
[[https://tug.org/pipermail/pstricks/|list archives]].```

- pgf: while pstricks is very powerful and

```  convenient from "traditional" TeX, using it with pdfLaTeX is
pretty tiresome: if you
simply want the graphical capabilities, [[ctanpkg>pgf|pgf]], together with
its "user-oriented" interface [[ctanpkg>tikz|tikz]], may be a good
bet for you.  While PDF has (in essence) the same graphical
capabilities as PostScript, it isn't programmable; [[ctanpkg>pgf|pgf]] provides
LaTeX commands that will utilise the graphical capabilities of
both PostScript and PDF equally.  [[ctanpkg>Pgf|Pgf]] has extensive
mathematical support, which allows it to rival [[ctanpkg>PSTricks|PSTricks]]'
use of the computation engine within PostScript.
The [[ctanpkg>pgf|pgf]] manual is enormous, but a simple introduction which
allows the user to get a feel for the capabilities of the system, is
available at <http://cremeronline.com/LaTeX/minimaltikz.pdf>```

- MetaPost; you liked MetaFont, but never got to grips with font files?

```  Try [[FAQ-MP|MetaPost]] ---
all the power of MetaFont, but it generates PostScript figures; MetaPost
is nowadays part of most serious (La)TeX distributions.  Knuth
uses it for all his work...```
```  Note that you can
[[FAQ-inlgrphapp|"embed" MetaPost source in your document]] (i.e.,
keep it in-line with your LaTeX code).```

- You liked MetaFont (or MetaPost), but find the language difficult?

```  ''Mfpic'' makes up MetaFont or MetaPost code for you using
familiar-looking (La)TeX macros.  Not //quite// the full power
of MetaFont or MetaPost, but a friendlier interface, and with MetaPost output
the results can be used equally well in either LaTeX or pdfLaTeX.```

- You liked PicTeX but don't have enough memory or time? Look

```  at the late Eitan Gurari's [[ctanpkg>dratex|dratex]]: it is just as powerful,
but is an entirely new implementation which is not as hard on
In addition, there are several means of generating code for your graphics application (`asymptote`, `gnuplot` and MetaPost, at least) in-line in your document, and then have them processed in a command spawned from your (La)TeX run. For details, see question.

format: plain


text:
＜テクニカルレポート＞Rule-Based Abduction for Logic Programming

作成者 作成者姓名 Hirata, Kouichi 平田, 耕一 所属機関 所属機関名 Research Institute of Fundamental Information Science Kyushu University 九州大学理学部附属基礎情報学研究施設 英語 Research Institute of Fundamental Information Science, Kyushu University 九州大学理学部附属基礎情報学研究施設 1995-03-25 RIFIS Technical Report 106 accepted open access In order to capture the nature of inference, a philosopher Peirce classified inference into three fundamental kinds: deduction, induction, and abduction. In this classification, which based on the for...m of syllogisms, abduction is characterized as the inference of a case A from a rule $A \rightarrow C$ and a result C. Furthermore, he also placed these three kinds of inference at each stage of scientific inquiry. According to him, every scientific inquiry begins with an observation of a surprising fact. The first stage, abduction, of scientific inquiry proposes a hypothesis to explain why the fact arises. The second stage, deduction, derives new conclusions from the hypothesis. The third stage, induction, tests empirically or corroborates the hypothesis and the conclusions. Hence, abduction is not only a kind of inference, but also a method of scientific discovery. The inference schema of abduction as the first stage of scientific inquiry is described in the following three steps: 1. A surprising fact C is observed. 2. If A were true, then C would be a matter of course. 3. Hence, there is reason to suspect that A is true. In computer science, the second stage, deduction, has been developed from viewpoints of automated theorem proving and logic programming. The third stage, induction, has been studied from viewpoints of inductive inference and machine learning. For the first stage, abduction, there are also many researches in various fields. In order to systematically understand them and clearly discuss abduction, first we classify abduction into five types: rule-selecting abduction, rule-finding abduction, rule-generating abduction, theory-selecting abduction, and theory-generating abduction. In this thesis, we examine such various researches on abduction so far developed, and show that most of them can be placed in our classification. Furthermore, we investigate the first three types of abduction, which we call together rule-based abduction, for logic programming. The rule-selecting abduction for logic programming is abduction which selects a rule in a program and proposes a hypothesis to explain a surprising fact. From the philosophical viewpoint we mentioned above, we should consider the process of abduction which terminates. Hence, it is a main purpose in this thesis to identify the class of logic programs for which the process of abduction terminates. We first introduce the concept of head-reducing programs. Then, we show that all the derivations for a head-reducing program and a surprising fact are finite. Hence, all the processes of rule-selecting abduction for a head-reducing program are finite. In general, abduction is closely related to nonmonotonic reasoning. Thus, in this thesis, we compare rule-selecting abduction with default logic. In order to formulate the rule-selecting abduction for default logic, we define a surprising fact and a hypothesis in the default logic. We show that, if there exists a hypothesis which explains a surprising fact, then there also exists an extension of a given default theory, which includes the surprising fact. This extension is corresponding to the least Herbrand model of the definite program obtaining from the default theory. Furthermore, we extend the concept of head-reducingness to that of breadth-first head-reducing programs, and the rule-selecting abduction to the breadth-first ruleselecting abduction. We also show that there exists a finite derivation for a breadthfirst head-reducing program and a surprising fact. Hence, the process of breadth-first rule-selecting abduction for a breadth-first head-reducing program is finite. The rule-finding abduction for logic programming is abduction which finds a rule in a program in the set of programs and proposes a hypothesis to explain a surprising fact. In rule-finding abduction, we are interested in how to choose programs from the set of programs. Then, we pay our attention to choosing programs for which the process of rule-finding abduction terminates. We introduce two concepts of loop-pair and loop-elimination. The loop-pair syntactically determines whether or not there exists an infinite process of rule-finding abduction for the choice of programs. We show that, if a loop-pair appears in a derivation, then the derivation becomes infinite. On the other hand, the loop-elimination is a transformation of programs. By using loop-elimination, we can choose the programs for which rule-finding abduction terminates. We also show that, for given two programs, if we transform one program by loop-elimination, then all the derivations for union of the transformed program and the rest are finite. In other words, by loop-elimination, we can choose the programs whose proof trees have no infinite branches. In this thesis, we also discuss analogical reasoning from the viewpoint of abduction. In this thesis, we adopt the formulation of analogical reasoning by Haraguchi and Arikawa. In their formulation, the main problem is how to detect an analogy. In order to solve this problem, we also adopt the concept of partial isomorphic generalizations. By using these concepts, we introduce the concept of deducible hypotheses, and formulate rule-finding abduction with analogy. We show that a deducible hypothesis is correct in the sense of analogical reasoning, and show that it is polynomial time computable with respect to the length of a surprising fact and the size of a proof tree. We design an algorithm of rule-finding abduction with analogy, and realize it as a Prolog program. The rule-generating abduction for logic programming is abduction which generates a rule and proposes a hypothesis to explain a surprising fact. In rule-generating abduction, only one surprising fact is given. In order to generate a rule and propose a hypothesis, we need to generalize the surprising fact. When we deal with generalizations, we should avoid overgeneralization. It should be determined whether or not a generalization is overgeneral by an intended model. However, it is hard to give in advance such an intended model in our rule-generating abduction. Hence, we introduce a syntactical generalization of one atom, called a safe generalization. In general, an atom is regarded as a relation between its arguments. Then, for safe generalizations, common ground terms are replaced by common variables. If the class of definite programs is not restricted to some subclass, there may be infinitely many meaningless hypotheses. Hence, we introduce the subclass of headreducing programs, called weakly 2-reducing programs. However, without any heuristic, the number of weakly 2-reducing rules for rule-generating abduction also increases in exponential order with respect to the length of a surprising fact. On the other hand, safe generalizations in this class are characterized by only two types of substitutions. Hence, by using two types of safe generalizations, we design an efficient algorithm of rule-generating abduction for weakly 2-reducing programs. The number of rules and hypotheses obtained by this algorithm is at most the number of the arguments in a surprising fact. We show that this algorithm generates rules and proposes hypotheses in polynomial time with respect to the length of a surprising fact. Furthermore, we show that the selected common list in some argument of a surprising fact appears in the same argument of the hypothesis proposed by this algorithm.続きを見る

本文情報を非表示

rifis-tr-106 pdf 6.56 MB
rifis-tr-106 pdf 6.56 MB 107

詳細

レコードID 3195 査読無 RIFIS Technical Report || 106 || p1-134 http://www.i.kyushu-u.ac.jp/research/report.html Ph.D.Thesis テクニカルレポート 2009.04.22 2017.01.20


text:
## Chemistry 9th Edition

a. $HClO_{4(aq)}\Rightarrow H^+_{(aq)}+ClO_{4(aq)}^-$ b. $CH_3CH_2CO_2H_{(aq)}\Rightarrow H^+_{(aq)}+CH_3CH_2CO_{2(aq)}^-$ c. $NH_{4(aq)}^+\Rightarrow H^+_{(aq)}+NH_{3(aq)}$
The dissociation of an acid is as follows: $HA\Rightarrow H^+ + A^-$ Therefore, because all three substances are acids the reactions are: $HClO_{4(aq)}\Rightarrow H^+_{(aq)}+ClO_{4(aq)}^-$ $CH_3CH_2CO_2H_{(aq)}\Rightarrow H^+_{(aq)}+CH_3CH_2CO_{2(aq)}^-$ $NH_{4(aq)}^+\Rightarrow H^+_{(aq)}+NH_{3(aq)}$


text:
SEARCH HOME
 Math Central Quandaries & Queries
 Question from Miura, a student: A city block is three times as long as long as it is wide.if the distance around the block is 0.48 kilometers, what is the area of the block in square meters?

Hi Miura,

First of all express the distance around the block, the perimeter, in meters.

Let $W$ be the width of the block in meters. The block is 3 times as long as it is wide so what is its length in terms of $W?$ What is the distance all the way around the block in terms of $W?$ You know this distance so this gives you an equation in $W.$ Solve for $W.$

Penny

Math Central is supported by the University of Regina and the Imperial Oil Foundation.


text:
2021 AIME I #8

(Note: I have the wrong problem number written in the video whiteboard.)

Find the number of integers $c$ such that the equation $||20|x|-x^2|-c|=21$ has $12$ distinct solutions.


text:
# evennia.commands.command¶

The base Command class.

All commands in Evennia inherit from the ‘Command’ class in this module.

exception evennia.commands.command.InterruptCommand[source]

Bases: Exception

Cleanly interrupt a command.

class evennia.commands.command.CommandMeta(*args, **kwargs)[source]

Bases: type

The metaclass cleans up all properties on the class

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class evennia.commands.command.Command(**kwargs)[source]

Bases: object

(you may see this if a child command had no help text defined)

Usage:

command [args]

This is the base command class. Inherit from this to create new commands.

The cmdhandler makes the following variables available to the command methods (so you can always assume them to be there): self.caller - the game object calling the command self.cmdstring - the command name used to trigger this command (allows

you to know which alias was used, for example)

cmd.args - everything supplied to the command following the cmdstring

(this is usually what is parsed in self.parse())

cmd.cmdset - the cmdset from which this command was matched (useful only

seldomly, notably for help-type commands, to create dynamic help entries and lists)

cmd.obj - the object on which this command is defined. If a default command,

this is usually the same as caller.

cmd.rawstring - the full raw string input, including any args and no parsing.

The following class properties can/should be defined on your child class:

key - identifier for command (e.g. “look”) aliases - (optional) list of aliases (e.g. [“l”, “loo”]) locks - lock string (default is “cmd:all()”) help_category - how to organize this help entry in help system

(default is “General”)

auto_help - defaults to True. Allows for turning off auto-help generation arg_regex - (optional) raw string regex defining how the argument part of

the command should look in order to match for this command (e.g. must it be a space between cmdname and arg?)

auto_help_display_key - (optional) if given, this replaces the string shown

in the auto-help listing. This is particularly useful for system-commands whose actual key is not really meaningful.

(Note that if auto_help is on, this initial string is also used by the system to create the help entry for the command, so it’s a good idea to format it similar to this one). This behavior can be changed by overriding the method ‘get_help’ of a command: by default, this method returns cmd.__doc__ (that is, this very docstring, or the docstring of your command). You can, however, extend or replace this without disabling auto_help.

key = 'command'
aliases = []
locks = 'cmd:all();'
help_category = 'general'
auto_help = True
is_exit = False
arg_regex = re.compile('^[ /]+.*$|$', re.IGNORECASE)
msg_all_sessions = False
retain_instance = False
__init__(**kwargs)[source]

The lockhandler works the same as for objects. optional kwargs will be set as properties on the Command at runtime, overloading evential same-named class properties.

lockhandler[source]
set_key(new_key)[source]

Update key.

Parameters

new_key (str) – The new key.

Notes

This is necessary to use to make sure the optimization caches are properly updated as well.

set_aliases(new_aliases)[source]

Replace aliases with new ones.

Parameters

new_aliases (str or list) – Either a ;-separated string or a list of aliases. These aliases will replace the existing ones, if any.

Notes

This is necessary to use to make sure the optimization caches are properly updated as well.

match(cmdname)[source]

This is called by the system when searching the available commands, in order to determine if this is the one we wanted. cmdname was previously extracted from the raw string by the system.

Parameters

cmdname (str) – Always lowercase when reaching this point.

Returns

result (bool) – Match result.

access(srcobj, access_type='cmd', default=False)[source]

This hook is called by the cmdhandler to determine if srcobj is allowed to execute this command. It should return a boolean value and is not normally something that need to be changed since it’s using the Evennia permission system directly.

Parameters
• srcobj (Object) – Object trying to gain permission

• access_type (str, optional) – The lock type to check.

• default (bool, optional) – The fallback result if no lock of matching access_type is found on this Command.

msg(text=None, to_obj=None, from_obj=None, session=None, **kwargs)[source]

This is a shortcut instead of calling msg() directly on an object - it will detect if caller is an Object or an Account and also appends self.session automatically if self.msg_all_sessions is False.

Parameters
• text (str, optional) – Text string of message to send.

• to_obj (Object, optional) – Target object of message. Defaults to self.caller.

• from_obj (Object, optional) – Source of message. Defaults to to_obj.

• session (Session, optional) – Supply data only to a unique session (ignores the value of self.msg_all_sessions).

Keyword Arguments
• options (dict) – Options to the protocol.

• any (any) – All other keywords are interpreted as th name of send-instructions.

execute_cmd(raw_string, session=None, obj=None, **kwargs)[source]

A shortcut of execute_cmd on the caller. It appends the session automatically.

Parameters
• raw_string (str) – Execute this string as a command input.

• session (Session, optional) – If not given, the current command’s Session will be used.

• obj (Object or Account, optional) – Object or Account on which to call the execute_cmd. If not given, self.caller will be used.

Keyword Arguments
• keyword arguments will be added to the found command (Other) –

• instace as variables before it executes. This is (object) –

• by default Evennia but may be used to set flags and (unused) –

• operating paramaters for commands at run-time. (change) –

at_pre_cmd()[source]

This hook is called before self.parse() on all commands. If this hook returns anything but False/None, the command sequence is aborted.

at_post_cmd()[source]

This hook is called after the command has finished executing (after self.func()).

parse()[source]

Once the cmdhandler has identified this as the command we want, this function is run. If many of your commands have a similar syntax (for example ‘cmd arg1 = arg2’) you should simply define this once and just let other commands of the same form inherit from this. See the docstring of this module for which object properties are available to use (notably self.args).

get_command_info()[source]

This is the default output of func() if no func() overload is done. Provided here as a separate method so that it can be called for debugging purposes when making commands.

func()[source]

This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse())

get_extra_info(caller, **kwargs)[source]

Display some extra information that may help distinguish this command from others, for instance, in a disambiguity prompt.

If this command is a potential match in an ambiguous situation, one distinguishing feature may be its attachment to a nearby object, so we include this if available.

Parameters
• caller (TypedObject) – The caller who typed an ambiguous

• handed to the search function. (term) –

Returns

A string with identifying information to disambiguate the object, conventionally with a preceding space.

get_help(caller, cmdset)[source]

Return the help message for this command and this caller.

By default, return self.__doc__ (the docstring just under the class definition). You can override this behavior, though, and even customize it depending on the caller, or other commands the caller can use.

Parameters
• caller (Object or Account) – the caller asking for help on the command.

• cmdset (CmdSet) – the command set (if you need additional commands).

Returns

docstring (str) – the help text to provide the caller for this command.

web_get_detail_url()[source]

Returns the URI path for a View that allows users to view details for this object.

ex. Oscar (Character) = ‘/characters/oscar/1/’

For this to work, the developer must have defined a named view somewhere in urls.py that follows the format ‘modelname-action’, so in this case a named view of ‘character-detail’ would be referenced by this method.

ex.

url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/\$',
CharDetailView.as_view(), name='character-detail')

If no View has been created and defined in urls.py, returns an HTML anchor.

This method is naive and simply returns a path. Securing access to the actual view and limiting who can view this object is the developer’s responsibility.

Returns

path (str) – URI path to object detail page, if defined.

web_get_admin_url()[source]

Returns the URI path for the Django Admin page for this object.

Returns

path (str) – URI path to Django Admin page for object.

client_width()[source]

Get the client screenwidth for the session using this command.

Returns

client width (int) – The width (in characters) of the client window.

styled_table(*args, **kwargs)[source]

Create an EvTable styled by on user preferences.

Parameters

*args (str) – Column headers. If not colored explicitly, these will get colors from user options.

Keyword Arguments

any (str, int or dict) – EvTable options, including, optionally a table dict detailing the contents of the table.

Returns

table (EvTable)

An initialized evtable entity, either complete (if using table kwarg)

styled_header(*args, **kwargs)[source]

styled_separator(*args, **kwargs)[source]
lock_storage = 'cmd:all();'
save_for_next = False
search_index_entry = {'aliases': '', 'category': 'general', 'key': 'command', 'no_prefix': ' ', 'tags': '', 'text': '\n ## Base command\n\n (you may see this if a child command had no help text defined)\n\n Usage:\n command [args]\n\n This is the base command class. Inherit from this\n to create new commands.\n\n The cmdhandler makes the following variables available to the\n command methods (so you can always assume them to be there):\n self.caller - the game object calling the command\n self.cmdstring - the command name used to trigger this command (allows\n you to know which alias was used, for example)\n cmd.args - everything supplied to the command following the cmdstring\n (this is usually what is parsed in self.parse())\n cmd.cmdset - the cmdset from which this command was matched (useful only\n seldomly, notably for help-type commands, to create dynamic\n help entries and lists)\n cmd.obj - the object on which this command is defined. If a default command,\n this is usually the same as caller.\n cmd.rawstring - the full raw string input, including any args and no parsing.\n\n The following class properties can/should be defined on your child class:\n\n key - identifier for command (e.g. "look")\n aliases - (optional) list of aliases (e.g. ["l", "loo"])\n locks - lock string (default is "cmd:all()")\n help_category - how to organize this help entry in help system\n (default is "General")\n auto_help - defaults to True. Allows for turning off auto-help generation\n arg_regex - (optional) raw string regex defining how the argument part of\n the command should look in order to match for this command\n (e.g. must it be a space between cmdname and arg?)\n auto_help_display_key - (optional) if given, this replaces the string shown\n in the auto-help listing. This is particularly useful for system-commands\n whose actual key is not really meaningful.\n\n (Note that if auto_help is on, this initial string is also used by the\n system to create the help entry for the command, so it\'s a good idea to\n format it similar to this one). This behavior can be changed by\n overriding the method \'get_help\' of a command: by default, this\n method returns cmd.__doc__ (that is, this very docstring, or\n the docstring of your command). You can, however, extend or\n replace this without disabling auto_help.\n '}


text:
PDA

View Full Version : Linking Error with GLUT

Caglow
07-31-2009, 03:27 PM
I am using the latest version of MinGW with Code::Blocks 8.02 along with OpenGL 3.1 and GLUT 3.7.

Normally, for GLUT/OpenGL projects, I use Microsoft Visual Studio to compile. I'm looking into cross platform development, however, and so I've decided to move many of my OS Portable projects to using GCC 4.4.0 with MinGW to modify the code to work with it. Actually, that was about a month ago.

This is my first time using GLUT on GCC and I've tried and failed what feels like 100 times. For every function I use in GLUT, I get a linking error along the lines of:

..\obj\glut.o:glutlib.c:(.text+0x45b)||undefined reference to __glutInitWithExit'|
..\obj\glut.o:glutlib.c:(.text+0x483)||undefined reference to glutInitDisplayMode'|
..\obj\glut.o:glutlib.c:(.text+0x4d8)||undefined reference to __glutCreateWindowWithExit'|
..\obj\glut.o:glutlib.c:(.text+0x5a7)||undefined reference to glutInitWindowSize'|
..\obj\glut.o:glutlib.c:(.text+0x60e)||undefined reference to glutDisplayFunc'|
..\obj\glut.o:glutlib.c:(.text+0x68e)||undefined reference to glutIdleFunc'|
..\obj\glut.o:glutlib.c:(.text+0x70e)||undefined reference to glutKeyboardFunc'|
..\obj\glut.o:glutlib.c:(.text+0x78e)||undefined reference to glutReshapeFunc'|
..\obj\glut.o:glutlib.c:(.text+0x7cc)||undefined reference to glutMainLoop'|
..\obj\glut.o:glutlib.c:(.text+0x7ec)||undefined reference to glutPostRedisplay'|
..\obj\glut.o:glutlib.c:(.text+0x80c)||undefined reference to `glutSwapBuffers'|
||=== Build finished: 11 errors, 0 warnings ===|

Yes, I've linked in all the libraries needed for GLUT and OpenGL. OpenGL actually works. It seems to link fine...just GLUT doesn't.

I thought it might be a problem with the libraries I built from source. I obtained another set from online pre-built for MinGW and had the exact same result. I tried with the libraries built as glut32.lib instead of libglut32.a and still had the same result...even after changing the linked library from glut32 to glut32.lib. I even tried changing the "linked libraries" section and putting them into Code::Blocks directly as command line arguments (-lopengl32 -lglut32) and had the same result.

Since I'm not using anything from GLU, I didn't link the library. I thought that might be the problem and added it in. Of course, it made absolutely no difference. I also tried linking in a whole set of other libraries like winms, gdi and other things I've never had to link but that still made no difference.

The following is the command line:
-pg -pedantic -Wmain -O3 -lglut32 -lopengl32

There were also the following pre-defined definitions which I don't know how to put in the command line:

WIN32
_DEBUG
_WINDOWS

NOTE: OpenGL was already present in MinGW. I added in GLUT which did not come with the package. Could it be a version mis-match? Doesn't sound like it from the errors. SDL which didn't come with MinGW works fine with OpenGL.

My code is strictly closed source (at least for now) but I can post small snippets which I doubt is necessary since this is a linking error.

Using Windows XP SP3 32 bit.

marshats
07-31-2009, 10:00 PM
One thing that looks suspicious to me is the "..\obj\glut.o" part of your error message. Are you trying to link directly to the .o file from the original source rather than the compiled library file that you should have installed in your linkers search path?

It may be worth a shot -- but try reversing the order of opengl32 and glut32 and capitalizing as GLUT32
"-pg -pedantic -Wmain -O3 -lopengl32 -lGLUT32"

A quick google search lead to setting up GLUT with code::blocks (http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/glut/) which may be helpful. This is probably a better approach.

On your second question, I don't use code blocks but gcc allows you to define settings on the command line with the "-D" for instance you mentioned
WIN32
_DEBUG
_WINDOWS
so you could try for instance -D_DEBUG to compile in debug mode.
ie "-pg -pedantic -Wmain -O3 -lopengl32 -lGLUT32 -D_DEBUG". Please note that this will not have anything to do with the linking error but will allow you to use global #DEFINE's in the source code.

Caglow
08-01-2009, 12:01 PM
I'm linking to the .a file. The glut.o file was something created from my own code. It's now glutlib.o.

marshats
08-01-2009, 04:52 PM
To try and debug the problem lets try with something simple. Can you compile and link the most basic glut code following without errors from within code:clocks:

#include <windows.h> //if your on windos
#include <GL/glut.h>

int main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitWindowSize(100, 100);

return 0;
}

also here is a more up to date url on setting up code:clocks with glut (http://codiecode.wordpress.com/2008/12/16/opengl-c-and-glut-using-codeblocks-and-mingw/) that you should try if the above fails

Caglow
08-07-2009, 07:01 PM
I copy and pasted the libglut32.a from cygwin and now it seems to work. A while later, I had trouble linking GLU but that was confined to one project only. I fixed it by deleting the glu32.dll library from .\bin. No idea how that would affect anything since a bad glu32.dll would only be a problem at runtime giving exceptions (at least from my experience). Strangely, it still doesn't work on cygwin; but I'm using MinGW so that doesn't matter. Of course, one problem fixed, another comes. This time, with windres.exe. It always gives me a problem about having "-x -c after last input file" and then gives me an error saying the file is not found. Of course, the file it says it can't find is THE FILE WITHOUT ANY PATH SEPARATORS! So it ends up saying something like "gcc: file or directory not found: EProjectsCIresource.rc not found." I'll post that somewhere else though since it doesn't appear to be an OpenGL problem.

ZbuffeR
08-09-2009, 04:58 AM
not gl related, but for the missing path separator, use forward slashes (unix style : /path/to/dir/ ) instead of backward slashes (dos style : \path\to\dir )

marshats
08-09-2009, 09:24 AM
an added comment on UNIX style and windows style path conventions: a common hurdle for people coming from windows is the use of the space charachter " " in the path/filename and what to do with the ":" part of the path specification. To use a space you must "escape" it with a backslash (\). And their is nothing special about the ":" it needs to be replaced with the normal UNIX path separator "/"

For example the exemplary windows applications folder

c:\Program Files\

in MinGS/msys is translated to

c/Program\ Files/

A possible alternative (I am not to familiar with Code::blocks so you may have to test the following) but you may be able to simply specify the windows path in quotes as follow:

c:\Program Files\

as

"c:\Program Files\"

Clive
09-08-2009, 12:05 PM
I had a similar problem getting GLUT to play with MinGW gcc just a week or so ago. I posted my issues/resolution on the MinGW mail list.

The glut32.dll, which I presume you will be linking to, is likely the one from Kilgard's website? It needed an import library which I tried in vain to build. Eventually I found one on the web named libglut32win.a -- which instantly solved my linking problems.
The Kilgard dll has undecorated __stdcall names which doesn't help the task of creating a good glut32.def file. With some editing, based on your linker errors, it should be possible to make a good .def file.

I was happy I got things linking but figured I'd try a 'somewhat' cleaner solution. I decided to try freeglut. I found a freeglut.dll (from version 2.4.0) and made an import library for it.

pexports freeglut.dll > freeglut.def
dlltool -d freeglut.def -l freeglut_win.a

This works fine.


text:
# Internal energy of n1 moles of hydrogen at temperature T is equal to the internal energy of n2 moles of helium at temperature 2T. Then the ratio n1/n2 is

Q: Internal energy of n1 moles of hydrogen at temperature T is equal to the internal energy of n2 moles of helium at temperature 2T. Then the ratio n1/n2 is

(a)3/5

(b)2/3

(c)6/5

(d)3/7

Solution :(c)
Internal energy of n moles of an ideal gas at temperature T is given by:

$\displaystyle U = \frac{1}{2}f n R T$

Where ,   (f = degrees of freedom)

U1 = U2

f1n1T1 = f2n2T2

n1/n2 = f2T2/f1T1 = 3×2/5×1 = 6/5

Here f2 = degrees of freedom of He = 3 and f1 = degrees of freedom of H2 = 5


text:
Code Generation, and other things

Fri 12 September 2014 — under ,

Long time, no post, but now I have news to share!

ufuncify stuff

First, I just merged a PR to make SymPy's ufuncify create actual instances of numpy.ufunc. This function takes in a tuple of arguments, and an expression, and returns a binary function that will broadcast (apply the function to each argument in turn) the arguments through the function, returning an array. An example would be:

from sympy import *
from sympy.utilities.autowrap import ufuncify
import numpy as np

# Create an example expression
a, b, c = symbols('a, b, c')
expr = sin(a) + cos(b**2)*c

# Create a binary (compiled) function that broadcasts it's arguments
func = ufuncify((a, b, c), expr)
func(np.arange(5), 2.0, 3.0)

array([-1.96093086, -1.11945988, -1.05163344, -1.81981085, -2.71773336])

Previously all broadcasting was done using hardcoded loops. These limited arguments to:

• A single dimension array (only for the first argument)
• Scalars for the remaining arguments
• Floating point arguments (no type conversion)

Now, through the magic of numpy.ufuncs:

• All arguments can be n-dimensional arrays
• Type conversion happens implicitly

This makes this functionality incredibly more useful. My next step is to add the ability for multiple outputs, and a custom wrapper so that matrix calculations can be broadcast as well. This should help with repeated computation of matrices, which is something Jason needs for his work. This should be done (hopefully) by the end of next week.

Code Generation Talk

I gave a talk yesterday on code generation in SymPy for our local Python User Group. Discusses the why and how of the code generation tool chains we developed, and gives a little demo. Slides are here, and the corresponding demo here.

Other things...

School recently started back up. In an effort to keep myself on task, I've started doing AIOs:

• Accomplishments: What did I do in the last week
• Issues: Things that came up and interfered with accomplishing things over the last week
• Objectives: Things I'd like to get done in the upcoming week. Note that these should be doable in ~1 week.

I've been hosting them on github in an effort to be open about my work, and update them every Friday. So far it seems to be a good idea - at the end of each week I get a chance to reflect on what I did that week, and what I plan to do over the next week. As a plus, my non-existant internet readers get to hold me accountable to my to-do list :).


text:
# An interesting problem about a “quasi ideal”

Let R be an infinite ring without an unity. Let I ⊆ R satisfying: for any a,b ∈ I, r ∈ R, we have a+b ∈ I, ar ∈ I, ra ∈ I. Then there are two possibilities about I:
(1) I must be an ideal, i.e., for any a ∈ I, we have -a ∈ I;
(2) there exists b ∈ I such that -b ∉ I.
Which one is right?

• Why do you believe that one of (1) and (2) has to be true in general? I mean, $I = R$ satisfies (1), but $I = 2\mathbb{Z}_{\geq 0} \subseteq 2 \mathbb{Z}$ satisfies (2). Also notice the third possibility $I = \emptyset$. – Matthias Klupsch Oct 16 '16 at 16:11
• Correct me again if I am wrong, but what happens when multiplication in $R$ is constant $0$? It seems to me that every subset which is additively closed then satisfies your conditions but not all of them need to contain additive inverses. – Matthias Klupsch Oct 17 '16 at 7:44


text:
# The Pyrex glass mirror in the telescope at the Mount Palomar Observatory (the Hale telescope) has a diameter of 200 in. The most extreme temperatures ever recorded on palomar Mountain are - 10°C and 50°C, Determine the maximum change in the diameter of the mirror.

28 Points
3 years ago
diameter =d=200 inc
change in temperature =$\Delta$T=50°-(-10°) = 60°C
cofficient of expansion for pyrax glass=$\alpha$=3.2×10^-6/C°
FORMULA:
$\Delta$L=$\Delta$$\alpha$×d
=60°C × 3.2×10^-6/C°× 200 inc
=38400 × 10^-6 inc
= 0.0384 inc

so, maximum increase in diameter is 0.0384 inc and total diameter after increase in temperature is = 200inc + 0.0384inc
= 200.0384 inc


text:
# American Institute of Mathematical Sciences

March  2013, 18(2): 467-482. doi: 10.3934/dcdsb.2013.18.467

## Periodic canard trajectories with multiple segments following the unstable part of critical manifold

 1 Institute for Information Transmission Problems, 19 Bolshoi Karetny, Moscow 127994, Russian Federation, National Research University Higher School of Economics, 20 Myasnitskaya Street, Moscow 101000 2 Department of Applied Mathematics, University College Cork, Ireland 3 Department of Applied Mathematics, University College, Cork

Received  October 2011 Revised  March 2012 Published  November 2012

We consider a scalar fast differential equation which is periodically driven by a slowly varying input. Assuming that the equation depends on $n$ scalar parameters, we present simple sufficient conditions for the existence of a periodic canard solution, which, within a period, makes $n$ fast transitions between the stable branch and the unstable branch of the folded critical curve. The closed trace of the canard solution on the plane of the slow input variable and the fast phase variable has $n$ portions elongated along the unstable branch of the critical curve. We show that the length of these portions and the length of the time intervals of the slow motion separated by the short time intervals of fast transitions between the branches are controlled by the parameters.
Citation: Alexander M. Krasnosel'skii, Edward O'Grady, Alexei Pokrovskii, Dmitrii I. Rachinskii. Periodic canard trajectories with multiple segments following the unstable part of critical manifold. Discrete & Continuous Dynamical Systems - B, 2013, 18 (2) : 467-482. doi: 10.3934/dcdsb.2013.18.467
##### References:

show all references

##### References:
 [1] Mi-Young Kim. Uniqueness and stability of positive periodic numerical solution of an epidemic model. Discrete & Continuous Dynamical Systems - B, 2007, 7 (2) : 365-375. doi: 10.3934/dcdsb.2007.7.365 [2] Erik Kropat, Silja Meyer-Nieberg, Gerhard-Wilhelm Weber. Singularly perturbed diffusion-advection-reaction processes on extremely large three-dimensional curvilinear networks with a periodic microstructure -- efficient solution strategies based on homogenization theory. Numerical Algebra, Control & Optimization, 2016, 6 (2) : 183-219. doi: 10.3934/naco.2016008 [3] Vladimir Sobolev. Canard cascades. Discrete & Continuous Dynamical Systems - B, 2013, 18 (2) : 513-521. doi: 10.3934/dcdsb.2013.18.513 [4] Zhiyuan Geng, Wei Wang, Pingwen Zhang, Zhifei Zhang. Stability of half-degree point defect profiles for 2-D nematic liquid crystal. Discrete & Continuous Dynamical Systems - A, 2017, 37 (12) : 6227-6242. doi: 10.3934/dcds.2017269 [5] Yaping Wu, Xiuxia Xing, Qixiao Ye. Stability of travelling waves with algebraic decay for $n$-degree Fisher-type equations. Discrete & Continuous Dynamical Systems - A, 2006, 16 (1) : 47-66. doi: 10.3934/dcds.2006.16.47 [6] Yaping Wu, Xiuxia Xing. Stability of traveling waves with critical speeds for $P$-degree Fisher-type equations. Discrete & Continuous Dynamical Systems - A, 2008, 20 (4) : 1123-1139. doi: 10.3934/dcds.2008.20.1123 [7] Andrejs Reinfelds, Klara Janglajew. Reduction principle in the theory of stability of difference equations. Conference Publications, 2007, 2007 (Special) : 864-874. doi: 10.3934/proc.2007.2007.864 [8] Guillaume Bal, Alexandre Jollivet. Generalized stability estimates in inverse transport theory. Inverse Problems & Imaging, 2018, 12 (1) : 59-90. doi: 10.3934/ipi.2018003 [9] G. Leugering, Marina Prechtel, Paul Steinmann, Michael Stingl. A cohesive crack propagation model: Mathematical theory and numerical solution. Communications on Pure & Applied Analysis, 2013, 12 (4) : 1705-1729. doi: 10.3934/cpaa.2013.12.1705 [10] Thi-Bich-Ngoc Mac. Existence of solution for a system of repulsion and alignment: Comparison between theory and simulation. Discrete & Continuous Dynamical Systems - B, 2015, 20 (9) : 3013-3027. doi: 10.3934/dcdsb.2015.20.3013 [11] Dominika Pilarczyk. Asymptotic stability of singular solution to nonlinear heat equation. Discrete & Continuous Dynamical Systems - A, 2009, 25 (3) : 991-1001. doi: 10.3934/dcds.2009.25.991 [12] Frédéric Mazenc, Michael Malisoff, Patrick D. Leenheer. On the stability of periodic solutions in the perturbed chemostat. Mathematical Biosciences & Engineering, 2007, 4 (2) : 319-338. doi: 10.3934/mbe.2007.4.319 [13] Freddy Dumortier, Robert Roussarie. Birth of canard cycles. Discrete & Continuous Dynamical Systems - S, 2009, 2 (4) : 723-781. doi: 10.3934/dcdss.2009.2.723 [14] Claudianor O. Alves. Existence of periodic solution for a class of systems involving nonlinear wave equations. Communications on Pure & Applied Analysis, 2005, 4 (3) : 487-498. doi: 10.3934/cpaa.2005.4.487 [15] Jingli Ren, Zhibo Cheng, Stefan Siegmund. Positive periodic solution for Brillouin electron beam focusing system. Discrete & Continuous Dynamical Systems - B, 2011, 16 (1) : 385-392. doi: 10.3934/dcdsb.2011.16.385 [16] Kaifa Wang, Aijun Fan. Uniform persistence and periodic solution of chemostat-type model with antibiotic. Discrete & Continuous Dynamical Systems - B, 2004, 4 (3) : 789-795. doi: 10.3934/dcdsb.2004.4.789 [17] Changrong Zhu, Bin Long. The periodic solutions bifurcated from a homoclinic solution for parabolic differential equations. Discrete & Continuous Dynamical Systems - B, 2016, 21 (10) : 3793-3808. doi: 10.3934/dcdsb.2016121 [18] Elena Shchepakina, Olga Korotkova. Canard explosion in chemical and optical systems. Discrete & Continuous Dynamical Systems - B, 2013, 18 (2) : 495-512. doi: 10.3934/dcdsb.2013.18.495 [19] Freddy Dumortier, Robert Roussarie. Canard cycles with two breaking parameters. Discrete & Continuous Dynamical Systems - A, 2007, 17 (4) : 787-806. doi: 10.3934/dcds.2007.17.787 [20] Michele V. Bartuccelli, G. Gentile, Kyriakos V. Georgiou. Kam theory, Lindstedt series and the stability of the upside-down pendulum. Discrete & Continuous Dynamical Systems - A, 2003, 9 (2) : 413-426. doi: 10.3934/dcds.2003.9.413

2018 Impact Factor: 1.008


text:
TxDb.Hsapiens.UCSC.hg19.knownGene and EnsDb.Hsapiens.v75 can't be installed

I think there is a problem with TxDb.Hsapiens.UCSC.hg19.knownGene and EnsDb.Hsapiens.v75. I'm struggling to install all of these packages as they pause at byte-compile and prepare package for lazy loading . Can anyone try to re-install them in their local machine because am not the only one who is having the problem, please? They used to work fine until a week ago!

As usual, I install the packages by:

BiocManager::install(c("Homo.sapiens", "EnsDb.Hsapiens.v75", "TxDb.Hsapiens.UCSC.hg19.knownGene"))

I also tried installing them individually:

BiocManager::install("EnsDb.Hsapiens.v75")
BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene")

It pause at:

* installing *source* package ‘TxDb.Hsapiens.UCSC.hg19.knownGene’ ...
** using staged installation
** R
** inst

sessionInfo( )

R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] BiocManager_1.30.10 compiler_4.0.3      tools_4.0.3

I've tried with and without RStudio. I'd be grateful if someone can try to replicate the error, please?

• Can you edit your question to include how you are trying to install the packages? thanks. Jan 1 at 13:18
• Sorry @user438383, I forgot to add how I installed the pacakges. I edited the question now and added more details.
– Sam
Jan 1 at 13:27
• Thanks. Just tried it on macOs 10.15 and it seems to have installed OK. Does the same problem occur if you try and install a different package via bioconductor, or a package using install.packages()? Jan 1 at 13:33
• Oh, thank you. This is extremely strange because I tried it on my friend's computer and had the same problem. I can install any other package via Bioconductor without problem except for these three. Can I ask if you installed all three of them?
– Sam
Jan 1 at 13:37
• It's been a week and I've tried uninstalling R, RStudio and RFrameworks  countless times but still not working. I'm sorry but can I ask if if you used BiocManager::install(c("Homo.sapiens", "EnsDb.Hsapiens.v75", "TxDb.Hsapiens.UCSC.hg19.knownGene")) to install them?
– Sam
Jan 1 at 13:39

I am able to successfully install these packages using:

BiocManager::install(c("Homo.sapiens", "EnsDb.Hsapiens.v75", "TxDb.Hsapiens.UCSC.hg19.knownGene"))

This completes without any errors / warnings (R v4.0.3 / macOS 10.16), so I don't believe the packages themselves/Bioconductor are 'broken', but I suspect you are having compiler issues due to the Big Sur update.

These are the steps I used to solve the problem:

1. Reinstall xcode command line tools (even if it says "up to date")
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

1. Install gcc & llvm via Homebrew (instructions for installing Homebrew) or, if you already have gcc/llvm installed via Homebrew, skip to the next step
# This can take several hours
brew install gcc
brew install llvm

1. Once you have gcc & llvm installed via Homebrew:
brew cleanup
brew update
brew reinstall gcc
brew reinstall llvm

sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

# You can safely ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists

1. Create a new ~/.R/Makevars file (if you already have a ~/.R/Makevars file, save it in a different directory (away from ~/.R/)) and include only these lines in the file:
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++

LLVM_LOC = /usr/local/opt/llvm
CC=/usr/local/gfortran/bin/gcc -fopenmp
CXX=/usr/local/gfortran/bin/g++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L$$(LLVM_LOC)/lib -Wl,-rpath,$$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I\$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

1. Compile a package from source in R/Rstudio
# To check whether openmp is enabled, compile data.table:
install.packages("data.table", type = "source")

1. If your package fails to compile, a couple of SO users have had to install a fresh gfortran (re: https://stackoverflow.com/a/65334247/12957340), which you can download from https://github.com/fxcoudert/gfortran-for-macOS/releases/tag/10.2-bigsur-intel

Once you can install packages from source without error/issue, update Bioconductor

BiocManager::install(version = "3.12")

Then, finally, you should be able to install your packages using

BiocManager::install(c("Homo.sapiens", "EnsDb.Hsapiens.v75", "TxDb.Hsapiens.UCSC.hg19.knownGene"))

• You are amazing Jared, I'll go through the steps right now to see if it works, fingers crossed.
– Sam
Jan 7 at 19:46
• Awesome, it is working now. Thank you so much, Jared :)
– Sam
Jan 16 at 2:12


text:
# Can we prove $\sum_{i=1}^m \frac{1}{t_i +1} \ge \sum_{i=1}^m \frac{1}{\lambda_i +1}$ or not?

Let $$t_1,\dots,t_m \ge 0$$, and $$\lambda_1, \dots, \lambda_m \ge 0$$. Suppose \begin{aligned} & t_1 + \dots + t_m = m(\lambda_1 + \dots + \lambda_m), \\ & t_1 \times \dots \times t_m \leq \lambda_1 \times \dots \times \lambda_m. \end{aligned} Can we prove the following inequality: $$$$\sum_{i=1}^m \frac{1}{t_i +1} \ge \sum_{i=1}^m \frac{1}{\lambda_i +1}.$$$$ I am stuck for a long time and have tried many methods, but have no idea at all. Can anyone prove it or provide a counterexample? Any help will be appreciated.

• How is this linear algebra? – Arturo Magidin Mar 18 at 3:17
• fine, I edited it. – Ze-Nan Li Mar 18 at 3:23
• the thing is close to majorization theory related to linear algebra in a way. – Toni Mhax Mar 18 at 3:50
• @ToniMhax Thanks for the hint ! – Ze-Nan Li Mar 18 at 3:51
• maybe $t_1+t_2=\lambda_1+\lambda_2$ yields the inequality when $m=2$. etc – Toni Mhax Mar 18 at 4:16

A preliminary calculation gives the following counterexample, $$m=2,t_1=\frac{3+\sqrt 7}{2}, t_2=\frac{3-\sqrt 7}{2}, \lambda_1=1,\lambda_2=\frac{1}{2}.$$ You can double check if it is indeed a counterexample or there is a mistake in my calculation.
• Actually, it should not be hard to check that under your conditions, the inequality is true if and only if $\lambda_1 \lambda_2\ge 1$. From this, it should be easy to get a counterexample. – QZ0 Mar 18 at 3:50
The sum constraint may be the wrong one if $$t_1=4$$ and $$t_2=0$$, $$\lambda_1=1.9$$, $$\lambda_2=0.1$$, $$$$\sum_{i=1}^2 \frac{1}{t_i +1}=1.2 \le \sum_{i=1}^2 \frac{1}{\lambda_i +1}\approx 1.25$$$$


text:
# Machine Learning Systems Design

Re-work Deep Learning Summit

### Artificial vs Natural Systems

• Consider natural intelligence, or natural systems
• Contrast between an artificial system and an natural system.
• The key difference between the two is that artificial systems are designed whereas natural systems are evolved.

### Natural Systems are Evolved

Survival of the fittest

?

### Natural Systems are Evolved

Survival of the fittest

Herbet Spencer, 1864

### Natural Systems are Evolved

Non-survival of the non-fit

### Mistake we Make

• Equate fitness for objective function.
• Assume static environment and known objective.

.

### Technical Consequence

• Classical systems design assumes decomposability.
• Data-driven systems interfere with decomponsability.

### Bits and Atoms

• The gap between the game and reality.
• The need for extrapolation over interpolation.

### Fragility of AI Systems

• They are componentwise built from ML Capabilities.
• Each capability is independently constructed and verified.
• Pedestrian detection
• Important for verification purposes.

### The Software Crisis

The major cause of the software crisis is that the machines have become several orders of magnitude more powerful! To put it quite bluntly: as long as there were no machines, programming was no problem at all; when we had a few weak computers, programming became a mild problem, and now we have gigantic computers, programming has become an equally gigantic problem.

Edsger Dijkstra (1930-2002), The Humble Programmer

### The Data Crisis

The major cause of the data crisis is that machines have become more interconnected than ever before. Data access is therefore cheap, but data quality is often poor. What we need is cheap high-quality data. That implies that we develop processes for improving and verifying data quality that are efficient.

There would seem to be two ways for improving efficiency. Firstly, we should not duplicate work. Secondly, where possible we should automate work.

Me

• Von Neuman Architecture:
• Code and data integrated in memory
• Today:
• Code and data separated for security

• Machine learning:
• Software is data
• Machine learning is a high level breach of the code/data separation.

### Peppercorns

• A new name for system failures which aren’t bugs.
• Difference between finding a fly in your soup vs a peppercorn in your soup.

### Conclusion

• AI is fundamentally ML System Design
• We are not ready to deploy automation in uncontrolled environments.
• Until we can monitoring and update will be key.


text:
Categories

# Cryptographic Wear-Out for Symmetric Encryption

As we look upon the sunset of a remarkably tiresome year, I thought it would be appropriate to talk about cryptographic wear-out.

### What is cryptographic wear-out?

It’s the threshold when you’ve used the same key to encrypt so much data that you should probably switch to a new key before you encrypt any more. Otherwise, you might let someone capable of observing all your encrypted data perform interesting attacks that compromise the security of the data you’ve encrypted.

The exact value of the threshold varies depending on how exactly you’re encrypting data (n.b. AEAD modes, block ciphers + cipher modes, etc. each have different wear-out thresholds due to their composition).

Let’s take a look at the wear-out limits of the more popular symmetric encryption methods, and calculate those limits ourselves.

## Specific Ciphers and Modes

### Cryptographic Limits for AES-GCM

I’ve written about AES-GCM before (and why I think it sucks).

AES-GCM is a construction that combines AES-CTR with an authenticator called GMAC, whose consumption of nonces looks something like this:

• Calculating H (used in GHASH for all messages encrypted under the same key, regardless of nonce):
• Encrypt(00000000 00000000 00000000 00000000)
• Calculating J0 (the pre-counter block):
• If the nonce is 96 bits long:
• NNNNNNNN NNNNNNNN NNNNNNNN 00000001 where the N spaces represent the nonce hexits.
• Otherwise:
• s = 128 * ceil(len(nonce)/nonce) - len(nonce)
• J0 = GHASH(H, nonce || zero(s+64) || int2bytes(len(nonce))
• Each block of data encrypted uses J0 + block counter (starting at 1) as a CTR nonce.
• J0 is additionally used as the nonce to calculate the final GMAC tag.

AES-GCM is one of the algorithms where it’s easy to separately calculate the safety limits per message (i.e. for a given nonce and key), as well as for all messages under a key.

#### AES-GCM Single Message Length Limits

In the simplest case (nonce is 96 bits), you end up with the following nonces consumed:

• For each key: 00000000 00000000 00000000 00000000
• For each (nonce, key) pair:
• NNNNNNNN NNNNNNNN NNNNNNNN 000000001 for J0
• NNNNNNNN NNNNNNNN NNNNNNNN 000000002 for encrypting the first 16 bytes of plaintext
• NNNNNNNN NNNNNNNN NNNNNNNN 000000003 for the next 16 bytes of plaintext…
• NNNNNNNN NNNNNNNN NNNNNNNN FFFFFFFFF for the final 16 bytes of plaintext.

From here, it’s pretty easy to see that you can encrypt the blocks from 00000002 to FFFFFFFF without overflowing and creating a nonce reuse. This means that each (key, nonce) can be used to encrypt a single message up to $2^{32} - 2$ blocks of the underlying ciphertext.

Since the block size of AES is 16 bytes, this means the maximum length of a single AES-GCM (key, nonce) pair is $2^{36} - 256$ bytes (or 68,719,476,480 bytes). This is approximately 68 GB or 64 GiB.

Things get a bit tricker to analyze when the nonce is not 96 bits, since it’s hashed.

The disadvantage of this hashing behavior is that it’s possible for two different nonces to produce overlapping ranges of AES-CTR output, which makes the security analysis very difficult.

However, this hashed output is also hidden from network observers since they do not know the value of H. Without some method of reliably detecting when you have an overlapping range of hidden block counters, you can’t exploit this.

(If you want to live dangerously and motivate cryptanalysis research, mix 96-bit and non-96-bit nonces with the same key in a system that does something valuable.)

#### Multi-Message AES-GCM Key Wear-Out

Now that we’ve established the maximum length for a single message, how many messages you can safely encrypt under a given AES-GCM key depends entirely on how your nonce is selected.

If you have a reliable counter, which is guaranteed to never repeat, and start it at 0 you can theoretically encrypt $2^{96}$ messages safely. Hooray!

You probably don’t have a reliable counter, especially in real-world settings (distributed systems, multi-threaded applications, virtual machines that might be snapshotted and restored, etc.).

Additionally (thanks to 2adic for the expedient correction), you cannot safely encrypt more than $2^{64}$ blocks with AES because the keystream blocks–as the output of a block cipher–cannot repeat.

Most systems that cannot guarantee unique incrementing nonces simply generate nonces with a cryptographically secure random number generator. This is a good idea, but no matter how high quality your random number generator is, random functions will produce collisions with a discrete probability.

If you have $2^n$ possible values, you should expect a single collision(with 50% probability) after $\sqrt{2^{n}}$ (or $2^{n/2}$)samples. This is called the birthday bound.

However, 50% of a nonce reuse isn’t exactly a comfortable safety threshold for most systems (especially since nonce reuse will cause AES-GCM to become vulnerable to active attackers). 1 in 4 billion is a much more comfortable safety margin against nonce reuse via collisions than 1 in 2. Fortunately, you can calculate the discrete probability of a birthday collision pretty easily.

If you want to rekey after your collision probability exceeds $2^{-32}$ (for a random nonce between 0 and $2^{96}$), you simply need to re-key after $2^{32}$ messages.

#### AES-GCM Safety Limits

• Maximum message length: $2^{36} - 256$ bytes
• Maximum number of messages (random nonce): $2^{32}$
• Maximum number of messages (sequential nonce): $2^{64}$ (but you probably don’t have this luxury in the real world)
• Maximum data safely encrypted under a single key with a random nonce: about $2^{68}$ bytes

### Cryptographic Limits for ChaCha20-Poly1305

The IETF version of ChaCha20-Poly1305 uses 96-bit nonces and 32-bit internal counters. A similar analysis follows from AES-GCM’s, with a few notable exceptions.

For starters, the one-time Poly1305 key is derived from the first 32 bytes of the ChaCha20 keystream output (block 0) for a given (nonce, key) pair. There is no equivalent to AES-GCM’s H parameter which is static for each key. (The ChaCha20 encryption begins using block 1.)

Additionally, each block for ChaCha20 is 512 bits, unlike AES’s 128 bits. So the message limit here is a little more forgiving.

Since the block size is 512 bits (or 64 bytes), and only one block is consumed for Poly1305 key derivation, we can calculate a message length limit of $2^{38} - 64$, or 274,877,906,880 bytes–nearly 256 GiB for each (nonce, key) pair.

The same rules for handling 96-bit nonces applies as with AES-GCM, so we can carry that value forward.

#### ChaCha20-Poly1305 Safety Limits

• Maximum message length: $2^{38} - 64$ bytes
• Maximum number of messages (random nonce): $2^{32}$
• Maximum number of messages (sequential nonce): $2^{96}$ (but you probably don’t have this luxury in the real world)
• Maximum data safely encrypted under a single key with a random nonce: about $2^{70}$ bytes

### Cryptographic Limits for XChaCha20-Poly1305

XChaCha20-Poly1305 is a variant of XSalsa20-Poly1305 (as used in libsodium) and the IETF’s ChaCha20-Poly1305 construction. It features 192-bit nonces and 32-bit internal counters.

XChaCha20-Poly1305 is instantiated by using HChaCha20 of the key over the first 128 bits of the nonce to produce a subkey, which is used with the remaining nonce bits using the aforementioned ChaCha20-Poly1305.

This doesn’t change the maximum message length, but it does change the number of messages you can safely encrypt (since you’re actually using up to $2^{128}$ distinct keys).

Thus, even if you manage to repeat the final ChaCha20-Poly1305 nonce, as long as the total nonce differs, each encryptions will be performed with a distinct key (thanks to the HChaCha20 key derivation; see the XSalsa20 paper and IETF RFC draft for details).

UPDATE (2021-04-15): It turns out, my read of the libsodium implementation was erroneous due to endian-ness. The maximum message length for XChaCha20-Poly1305 is $2^{64}$ blocks, and for AEAD_XChaCha20_Poly1305 is $2^{64} - 1$ blocks. Each block is 64 bytes, so that changes the maximum message length to about $2^{70}$. This doesn’t change the extended-nonce details, just the underlying ChaCha usage.

#### XChaCha20-Poly1305 Safety Limits

• Maximum message length: $2^{70}$ bytes (earlier version of this document said $2^{38} - 64$)
• Maximum number of messages (random nonce): $2^{80}$
• Maximum number of messages (sequential nonce): $2^{192}$ (but you probably don’t have this luxury in the real world)
• Maximum data safely encrypted under a single key with a random nonce: about $2^{118}$ bytes

### Cryptographic Limits for AES-CBC

It’s tempting to compare non-AEAD constructions and block cipher modes such as CBC (Cipher Block Chaining), but they’re totally different monsters.

• AEAD ciphers have a clean delineation between message length limit and the message quantity limit
• CBC and other cipher modes do not have this separation

Every time you encrypt a block with AES-CBC, you are depleting from a universal bucket that affects the birthday bound security of encrypting more messages under that key. (And unlike AES-GCM with long nonces, AES-CBC’s IV is public.)

This is in addition to the operational requirements of AES-CBC (plaintext padding, initialization vectors that never repeat and must be unpredictable, separate message authentication since CBC doesn’t provide integrity and is vulnerable to chosen-ciphertext atacks, etc.).

For this reason, most cryptographers don’t even bother calculating the safety limit for AES-CBC in the same breath as discussing AES-GCM. And they’re right to do so!

If you find yourself using AES-CBC (or AES-CTR, for that matter), you’d best be performing a separate HMAC-SHA256 over the ciphertext (and verifying this HMAC with a secure comparison function before decrypting). Additionally, you should consider using an extended nonce construction to split one-time encryption and authentication keys.

However, for the sake of completeness, let’s figure out what our practical limits are.

CBC operates on entire blocks of plaintext, whether you need the entire block or not.

On encryption, the output of the previous block is mixed (using XOR) with the current block, then encrypted with the block cipher. For the first block, the IV is used in the place of a “previous” block. (Hence, its requirements to be non-repeating and unpredictable.)

This means you can informally model (IV xor PlaintextBlock) and (PBn xor PBn+1) as a pseudo-random function, before it’s encrypted with the block cipher.

If those words don’t mean anything to you, here’s the kicker: You can use the above discussion about birthday bounds to calculate the upper safety bounds for the total number of blocks encrypted under a single AES key (assuming IVs are generated from a secure random source).

If you’re okay with a 50% probability of a collision, you should re-key after $2^{64}$ blocks have been encrypted.

If your safety margin is closer to the 1 in 4 billion (as with AES-GCM), you want to rekey after $2^{48}$ blocks.

However, blocks encrypted doesn’t map neatly to bytes encrypted.

If your plaintext is always an even multiple of 128 bits (or 16 bytes), this allows for up to $2^{52}$ bytes of plaintext. If you’re using PKCS#7 padding, keep in mind that this will include an entire padding block per message, so your safety margin will deplete a bit faster (depending on how many individual messages you encrypt, and therefore how many padding blocks you need).

On the other extreme (1-byte plaintexts), you’ll only be able to eek $2^{48}$ encrypted bytes before you should re-key.

Therefore, to stay within the safety margin of AES-CBC, you SHOULD re-key after $2^{48}$ blocks (including padding) have been encrypted.

Keep in mind: $2^{48}$ single-byte blocks is still approximately 281 TiB of data (including padding). On the upper end, $2^{48}$ 15-byte blocks (with 1-byte padding to stay within a block) clocks in at about $2^{51.9}$ or about 4.22 PiB of data.

#### That’s Blocks. What About Bytes?

The actual plaintext byte limit sans padding is a bit fuzzy and context-dependent.

The local extrema occurs if your plaintext is always 16 bytes (and thus requires an extra 16 bytes of padding). Any less, and the padding fits within one block. Any more, and the data:padding ratio starts to dominate.

Therefore, the worst case scenario with padding is that you take the above safety limit for block counts, and cut it in half. Cutting a number in half means reducing the exponent by 1.

But this still doesn’t eliminate the variance. $2^{47}$ blocks could be anywhere from $2^{47}$ to $2^{50.9}$ bytes of real plaintext. When in situations like this, we have to assume the worst (n.b. take the most conservative value).

Therefore…

#### AES-CBC Safety Limits

• Maximum data safely encrypted under a single key with a random nonce: $2^{47}$ bytes (approximately 141 TiB)

## Take-Away

Compared to AES-CBC, AES-GCM gives you approximately a million times as much usage out of the same key, for the same threat profile.

ChaCha20-Poly1305 and XChaCha20-Poly1305 provides even greater allowances of encrypting data under the same key. The latter is even safe to use to encrypt arbitrarily large volumes of data under a single key without having to worry about ever practically hitting the birthday bound.

I’m aware that this blog post could have simply been a comparison table and a few footnotes (or even an IETF RFC draft), but I thought it would be more fun to explain how these values are derived from the cipher constructions.

## 20 replies on “Cryptographic Wear-Out for Symmetric Encryption”

noncesays:

So when you are encrypting your videos or photos, how do you actually keep track of how much data you have encrypted with the same key or nonce? Is this something that a key management solution like Java KeyStore can help with?

[…] cryptography), and can be safely implemented at relatively large sizes (e.g. for encrypting practically unlimited data under a single key), modern symmetric cryptography research is likely to focus on […]

[…] For example, ChaCha20-Poly1305 accepts a 256-bit key and 96-bit nonce (with an internal 32-bit block counter). If you generate the nonce randomly, you should expect a collision with probability 2^-32 after 2^32 messages. […]

Lonjilsays:

I believe that Libsodium’s XChaCha20-Poly1305 actually uses a 64 bit counter, so messages can be quite large.

This actually allows for 2^64-1 blocks, or about 2^70 byte messages.

lonjilsays:

I was going off of the libsodium docs, which cite the 2**64-1 number. I believe there has been some confusion over it this point, actually, something about the RFC and libsodium disagreeing on this point? I don’t know because I haven’t read it, but I’ve seen this 32 vs 64 bit counter thing come up several times.

Yep, it turns out you were right, and I’ve corrected the blog post.

lonjilsays:

Thank you! Really enjoying your blog, btw. Got into crypto stuff recently and found your postings yesterday. Illuminating and fun to read.

[…] For added fun, let’s assume you’re using HKDF-HMAC-SHA512 with a 256-bit salt to derive separate a separate encryption keys and MAC keys from the input key. This salt is prepended to the ciphertext and included as an input to the HMAC tag calculation. Now you don’t have to worry about cryptographic wear-out. […]

AVsays:

what about XTS? Can you calculate the wear out for XTS as well?

XTS is morally equivalent to CBC here.

Ron Keidarsays:

As XTS is the mode used for storage, (RAM and disk), and can work on parallel blocks (worn fast), hence it is interesting for the industry. Question: in XTS the attacker does not see the plaintext and ciphertext of the internal AES. Can we say that because of that it may worn out for a given tweak/address, but if the collection of information is spread all over (if attacker cannot control memory address), the collision of different tweaks do not build up to a single BDay attack but rather parallel attacks that do not wear the key at the same rate?

The underlying mechanics of XTS mode don’t really matter here. You’re working with 128-bit blocks and reasoning about collision probabilities thereof.

XTS mode behaves like CBC mode, except you XOR the plaintext *and* ciphertext with the same IV (and there’s an additional encryption step from a “tweak key”), and use Galois Field multiplication instead of XOR to calculate the next IV. This effectively hides the IV from the ciphertext, but that addresses security properties irrelevant to our discussion.

When talking about symmetric wear-out, you’re only concerned with the inputs and outputs of the encryption function. XTS mode reduces to AES(IV xor plaintext, static key) xor IV. You’ll get a single IV collision after encrypting 2^64 blocks (with 50% probability).

Whether or not you can pivot from this first collision to a practical attack is an exercise left to the reader. Although with block-level encryption and how many filesystems encode data at a low level, you’ll likely have enough redundancy to collide (IV, plaintext) pairs at some point in excess of this threshold.

Thus, the discussions of XTS mode don’t really warrant a separate section.

[…] year, I wrote about cryptographic wear-out for symmetric encryption. That post has attracted quite a bit of feedback from folks requesting comparisons against other […]

[…] Threema’s MasterKey class has an API used elsewhere throughout the application that encrypts and decrypts files using AES/CBC/PKCS5Padding. This mode is widely known to be vulnerable to padding oracle attacks, and has a worse wear-out story than other AES modes. […]

[…] HKDF is used to derive a uniformly-random secret key for used with symmetric cryptography algorithms. In any situation where a key might need to be derived, you might see HKDF being used. (Although, […]

[…] records (or the same wrapping key for multiple data keys), you’re going to read up on symmetric wear-out and the birthday […]

[…] However, one of my gripes technically belongs in both categories: The small nonce size, which is caused by AES’s block size, limits the amount of data you can safely encrypt with a single symmetric key. […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.


text:
# What weight of the non-volatile solute, urea ($NH_2 - CO -NH_2$) need to be dissolved in 100g of water, in order to decrease the vapour pressure of water by 25%? What will be the molality of the solution?

18.52
Hence (C) is the correct answer.


text:
How would I take the laplace transform of f(t)= te^tsin^2(t)?

Tags:
1. Nov 15, 2015

Jim wah

How would I take the laplace transform of f(t)= te^tsin^2(t)?

Last edited: Nov 15, 2015
2. Nov 15, 2015

DevacDave

You mean t et sin(2t)? What's causing you the problem? It is pretty straight-forward application of the definition case.

3. Nov 15, 2015

Jim wah

No the equation is f(t)= te^tsin^2(t)

4. Nov 15, 2015

DevacDave

Still, it's a standard case (I have a vague recall of this exact function class being important in telecommunication). Perfectly doable via integration by parts. Is this where you got stuck?

5. Nov 15, 2015

Jim wah

Kinda, Is there anyway to figure out the transform of sin^2(t) then use the theorem for the e^t and t?

6. Nov 15, 2015

jack476

I don't know of having seen that in a table anywhere, it doesn't look like an elementary form, so what you need to do is compute the transform directly using the Laplace transformation definition.
For integrating the sin2(t) in the transformation integral you need to use the half-angle formula: http://www.sosmath.com/trig/douangl/douangl.html

7. Nov 15, 2015

Jim wah

Thank you so much!


text:
# Length of a Cardioid

1. Apr 23, 2007

### Bazman

Hi,

The final answer below is wrong. Is should be 8a! Not sure where I made the error below?

Also is there another substitution that can be used at the earlier line
$$a \int_0^{2 \pi} \{ 2( 1 - \sin \phi) \}^{\frac{1}{2}} d\phi$$
to subtitute for the $$(1 - \sin \phi)$$ without the need to use
$$s = \frac{\pi}{2} - t$$.

This would also be very useful for the next part where I have to calculate the area of surface of revolution!!

(ii)

$$L = \int_0^{2 \pi} \{ r^2 + (\frac{dr}{d \theta})^2 \}^{\frac{1}{2}} d \phi$$

$$\int_0^{2 \pi} \{ a^2(1- \sin \phi)^2 + (-a \cos \phi)^2 \}^{\frac{1}{2}} d\phi$$

$$a \int_0^{2 \pi} \{ 2( 1 - \sin \phi) \}^{\frac{1}{2}} d\phi$$

using $$s = \frac{\pi}{2} - t$$

$$\frac{ds}{dt} = -1$$

$$-a \int_{\frac{\pi}{2}}^{\frac{-3\pi}{2}} \{ 2( 1 - \cos \phi) \}^{\frac{1}{2}} d\phi$$

$$a \int_{\frac{-3\pi}{2}}^{\frac{\pi}{2}} \{ 4 \sin^2 (\frac{\phi}{2}) \}^{\frac{1}{2}} d\phi$$

$$a \int_{\frac{-3\pi}{2}}^{\frac{\pi}{2}} \{ 2 \sin (\frac{\phi}{2} \} d\phi$$

$$a [ -4 \cos (\frac{\phi}{2} ]_{\frac{-3\pi}{2}}^{\frac{\pi}{2}}$$

$$= 4a(\frac{1}{2 \sqrt{2}})$$

2. Apr 27, 2007

### pizzasky

Note that $$a \int_{\frac{-3\pi}{2}}^{\frac{\pi}{2}} \sqrt{4 \sin^2 (\frac{\phi}{2}) } \ d\phi = 2a \int_{\frac{-3\pi}{2}}^{\frac{\pi}{2}} \mid \sin (\frac{\phi}{2}) \mid d\phi$$

Last edited: Apr 27, 2007
3. Apr 28, 2007

### Bazman

ah got it!

Thanks Pizzasky

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook


text:
## Chemistry: The Molecular Science (5th Edition)

Published by Cengage Learning

# Chapter 15 - Additional Aqueous Equilibria - Problem Solving Practice 15.7 - Page 673: a

#### Answer

$pH = 4.14$

#### Work Step by Step

- Find the numbers of moles: $C(CH_3COOH) * V(CH_3COOH) = 0.1* 0.05 = 5 \times 10^{-3}$ moles $C(NaOH) * V(NaOH) = 0.1* 0.01 = 1 \times 10^{-3}$ moles Write the acid-base reaction: $CH_3COOH(aq) + NaOH(aq) -- \gt NaCH_3COO(aq) + H_2O(l)$ - Total volume: 0.05 + 0.01 = 0.06L Since the base is the limiting reactant, only $0.001$ mol of the compounds will react. Therefore: Concentration (M) = $\frac{n(mol)}{Volume(L)}$ $[CH_3COOH] = 0.005 - 0.001 = 0.004$ moles. Concentration: $\frac{ 0.004}{ 0.06} = 0.06666M$ $[NaOH] = 0.001 - 0.001 = 0$ $[NaCH_3COO] = 0 + 0.001 = 0.001$ moles. Concentration: $\frac{ 0.001}{ 0.06} = 0.01667M$ - Calculate the $pK_a$ for the acid $pKa = -log(Ka)$ $pKa = -log( 1.8 \times 10^{- 5})$ $pKa = 4.745$ - Using the Henderson–Hasselbalch equation: $pH = pKa + log(\frac{[Base]}{[Acid]})$ $pH = 4.745 + log(\frac{0.01667}{0.06666})$ $pH = 4.745 + log(0.25)$ $pH = 4.745 + -0.602$ $pH = 4.143$

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.


text:
# High torque cage induction motor

Discussion in 'Homework Help' started by Jess_88, Sep 26, 2011.

1. ### Jess_88 Thread Starter Member

Apr 29, 2011
174
1
Hey guys
I'm a bit confused with this question.

Given the high torque cage induction motor name plate data

and the full equivalent circuits parameters

The friction and windage loss is 0.910 kW and may be considered constant
over speed range 1500 rev/min to 1000 rev/min.

It is required to control the speed of the motor over a limited range by voltage control.

I need to determine for a motor speed of 1355 rev/min:
a) the required stator line voltage;
b) the motor efficiency at 1355 rev/min;
c) comment on the suitability of running the motor in this reduced voltage mode.

I'm finding it difficult to fined much information on this kind of question. For part 'a', isn't the stator line voltage = (√3)(Phase voltage)?
Is phase voltage = 415V

I can't see how how the motor speed relates to the voltage Can anyone show me the formulas required in this?

I also can't fined anything on determining the efficiency at a given speed.

Thanks a lot guys

2. ### t_n_k AAC Fanatic!

Mar 6, 2009
5,448
790
Which equivalent circuit model are you expected to use? What have you been taught as the working schematic form? There are a couple of options. The model is usually derived on a per-phase basis.

If you know the speed you can find the slip 's'.

The per phase rotor power is related to the rotor equivalent resistance which is normally given as R2/s.

With no mechanical load, the rotor power is simply equivalent to windage and friction losses - which must be per phase. So you can find the effective rotor current [per phase]. From the model you can then derive the stator input line-to-neutral voltage. This line to neutral value can then be converted to a line-to-line value.

Jess_88 likes this.
3. ### Jess_88 Thread Starter Member

Apr 29, 2011
174
1
I'm think this is the equivalent circuit model

so would the line current be I1?
Sorry, I'm still a bit lost

4. ### t_n_k AAC Fanatic!

Mar 6, 2009
5,448
790
OK - it's important to know which model you have.

It's possible you may have been taught that the following relationships hold. For a poly-phase induction machine.

Total Air Gap Power=p*I2^2*R2/s

Total Rotor Copper Loss=p*I2^2*R2

Total Shaft power=Total Air Gap Power- Total Rotor Copper Loss

Hence Total Shaft Power=p*I2^2*(1-s)/s

'p' is the number of phases & 's' is the slip.

In this case p=3.

You are asked to find the voltage that would run the machine at 1355 rpm - presumably with no mechanical load.

The only mechanical load then that the motor 'sees' is 910W - due to windage and friction loss.

This would be the total shaft power

So

910=3*I2^2*0.293(1-s)/s

The slip will be s=1-1355/1500=0.0967

This will therefore allow you to find the unknown I2.

Once you have I2 it's relatively simple circuit theory to find I1 - which is indeed the AC line current. Hence you will also be able to find the input phase voltage $V_\phi$. You will have the voltage and current as complex phasors so you should then be able to deduce the input power factor knowing the phase displacement between the current I1 & voltage $V_\phi$.

Efficiency can also be deduced by calculating the input power and doing the efficiency calculation with the shaft power as the result - in this case simply the windage & friction losses as the notional shaft mechanical output power.

Jess_88 likes this.
5. ### Jess_88 Thread Starter Member

Apr 29, 2011
174
1
ah ok.
so I get I2 = 9.08A
Then I would use I1 = 64A -I2 - IM right?
I was thinking I would determine IM from the Air gap Power loss. But I see you have
Total Air Gap Power=p*I2^2*R2/s. I would have thought you would use IM

6. ### t_n_k AAC Fanatic!

Mar 6, 2009
5,448
790
Yes - You must include the magnetizing current to find the current I1.

How did you arrive at 9.08A for I2?

If the mechanical output is 910W

then from the aforementioned formula (my post #4)

I2=√(910/(3*0.293*0.9345))=10.525A

7. ### Jess_88 Thread Starter Member

Apr 29, 2011
174
1
ah, yeah I made a mistake in my math.
How would I go about determining Im

8. ### t_n_k AAC Fanatic!

Mar 6, 2009
5,448
790
E1=I1*(R2/s+jX2)

Im=E1/Zm

Where Zm=Rc||jXc