Evaluating expressions in “case” vs using “if/else if”

I was just tempted to write a similar piece of code to the one presented in this answer on SO (posted below). The problem is having to discriminate between different cases where exactly one case is true.

In my experience switch statements are usually use to match the value of an expression against various constants. But in this case we use a switch statement to decide which of the conditions is true. To do this I would actually prefer using if/else if because switch(true) feels a little bit like an abuse of switch, but this is just a gut feeling. On the other hand I think this piece of code is still prefectly readable even with its seemingly unconventional use of a switch statement.

Are there any objective reasons why one would prefer switch over if/else if or vice versa when it comes to code quality, performance and readability?

switch (true) {   case (amount >= 7500 && amount < 10000):     //code     break;   case (amount >= 10000 && amount < 15000):     //code     break;    //etc... 

Evaluating Dirichlet $L$-functions at $s=1$

I’m trying to find references on general methods for evaluating Dirichlet $ L$ -functions at $ s=1$ , but it’s proving a little harder to google than I’d hoped. Specifically I’m looking for any books or papers that go through methods for solving the following question: suppose I have a (possibly primitive) Dirichlet character $ \chi$ of conductor $ q$ , what is the value of $ L(1,\chi)$ ? Any insights anyone has about this that aren’t a book or paper would also be very much appreciated.

This question has a good amount of detail on how to approach the problem, but it only covers odd characters. The Wikipedia page for the analytic class number formula also has this section, which gives closed forms for $ L$ -functions at $ s=1$ , but this is only for primitive characters with prime conductors (and possibly only for quadratic characters?) This is as much as I could find, and as for the more general cases I’m at a bit of a loss.

Evaluating part(s) of a function which outputs another function [duplicate]

This question already has an answer here:

  • Evaluation in lambda function 2 answers

I would like to define a function f(n) which outputs another function as follows:

f[n_] := PolynomialRemainder[#,ChebyshevT[n,x],x]& 

However, I would like the ChebyshevT[n,x] part of the function to be evaluated when f is called, so that for instance when f(2) is evaluated I get PolynomialRemainder[#,-1+2x^2,x]& instead of PolynomialRemainder[#,ChebyshevT[2,x],x]&.

How do I do that? If I wrap the function body in an Evaluate as follows:

f[n_] := Evaluate[PolynomialRemainder[#,ChebyshevT[n,x],x]]& 

then the whole definition gets evaluated, and the input # is assumed to be free of x, resulting in f[2] = #&.

Problem in evaluating logarithm and derivative

My apologies regarding formatting; I am not the best with the math syntax here yet.

Given the property of the logarithm that log(xy) = log(x) + log(y), how would one take the ‘derivative’ of this?

To be more clear,

log(xy) = log(x) + log(y) (property of log)

D(log(xy)) = D(log(x) + log(y)) (i) (Take derivative on both sides)

Now, D(log(x) + log(y)) = D(log(x)) + D(log(y)) (ii) (Derivative of sum is sum of derivatives)

Combining (i) and (ii): D(log(xy)) = D(log(x)) + D(log(y))

Implies: 1/xy = 1/x + 1/y (Evaluate derivative of logarithm using D(log(x)) = 1/x)

1 / xy = 1/x + 1/y looks false to me; e.g. while log(6) does equal log(2) + log(3), 1/6 does not equal 1/2 + 1/3.

I would think the function 1/x does not obey f(xy) = f(x) + f(y). What’s going wrong in this example?

undefined is not an object (‘evaluating _this.props.navigation.navigate’)

I’m new programing with React Native and I got this issue with my code, I’m try to do a Splash screen and after that I want to make a Login that redirect me to another screen.

The Splash screen run well but when I’m in the Login Screen and I push the “Entrar” button, it crashes and shows the message.

`

import React from 'react'; import { Image, Text, View } from 'react-native'; import { Asset, SplashScreen } from 'expo';  import Splash from './screens/Splash'; import Login from './screens/Login'; import ForgotPass from './screens/ForgotPass'; import Home from './screens/Home';  App.js  export default class App extends React.Component {   componentWillMount()   {     this.setState({       view: <Splash />     })      setTimeout(() => {       this.setState({         view: <Login />       })     }, 3000)   }    render()   {     return(       this.state.view     )   } }  ////////////////////////////////////////////////////////////  Login.js  import React from 'react'; import { View, BackHandler } from 'react-native'; import { Card, Button, FormLabel, Text, FormInput } from 'react-native-elements'; import { createStackNavigator, navigate } from 'react-navigation';  export default class Login extends React.Component {   static navigationOptions = {     title: 'Iniciar sesión',     headerLeft: null,   }    componentDidMount()   {     BackHandler.addEventListener('hardwareBackPress', function()     {       return true;     });   }    render()   {     return (       <View style={{ paddingVertical: 20 }}>         <Card>           <FormLabel>Nombre de Usuario</FormLabel>           <FormInput placeholder='NombreUsuario' />           <FormLabel>Contraseña</FormLabel>           <FormInput secureTextEntry placeholder='Contraseña' />            <Button             buttonStyle={{ marginTop: 20 }}             backgroundColor='#03A9F4'             title='Entrar'             onPress={() => this.props.navigation.navigate('Home')}           />         </Card>         <View style={{ paddingVertical: 20 }}>           <Button             title="¿Olvidó su contraseña?"             onPress={() => this.props.navigation.navigate('ForgotPass')}           />         </View>       </View>     );   } }` 

Evaluating complicated limits correctly

Let say I have defined some function:

a[x_] = x^2 Log[x^2].

If I try to evaluate a[0] Mathematica will complain that it is indeterminate, but if I evaluate Limit[a[x],x->0] I get the correct answer.

My problem is that my function is a function of very many variables that I wish to send to zero, and it contains a few instances of the form (x^2 + y^2 + ...)Log[x^2 + y^2 + ...]. (But not all of exactly the same form, so there is no obvious change of variables I can do.)

If I try to take the limit Limit[f[x,y,...],{x->0, y->0, ...}], Mathematica will take a very long time to give me the answer, and if I try f[0,0,...], I get Indeterminate. However from inspection I know that most of the terms should go to zero and the final result will be finite.

I’m wondering if there is a fast way to get Mathematica to evaluate these limits correctly?

Why isn’t my function evaluating to an explicit number?

I’m just wondering why my function is not evaluating as I think it should. I put in the following:

dp = {{0, 71}, {1, 71}, {2, 71}, {3, 70}, {4, 69}, {5, 67}, {6,65}, {7, 63}, {8, 61}, {9, 60}, {10, 60}, {11, 61}, {12, 63}, {13,65}, {14, 66}, {15, 67}, {16, 67}, {16, 67}, {17, 66}, {18,65}, {19, 63}, {20, 60}, {21, 58}, {22, 56}, {23, 55}}; f = Fit[dp, {1, x, x^2, x^3, x^4, x^5, x^6, x^7}, x]; f[3] 

but as output I get

(71.121 - 1.29633 x + 1.34837 x^2 - 0.504693 x^3 + 0.0700859 x^4 - 0.00447611 x^5 + 0.000134178 x^6 - 1.53469*10^-6 x^7)[3] 

The output I want is the polynomial’s value at x=3.