Linked Questions

1
vote
2answers
78 views

The difference between ? and /; [duplicate]

I can do the following Cases[Range@10, x_ /; OddQ[x]] But why cannot I do x_?OddQ[x] instead of ...
0
votes
0answers
68 views

Condition in a replacing function [duplicate]

Because of "Thou shalt not copypaste", I'd like to change my pair of replacements F[foo_,foo_+1]:=bar;F[foo_,foo_-1]:=bar; (it's MUCH longer, so it actually ...
0
votes
1answer
77 views

How to use Strings and Functions With Conditions

Very new to Mathematica so this might be really simple. I have the function pow[x_,r_]:= x^r where r is rational due to ...
6
votes
2answers
4k views

How to restrict the domain of a function

I realize this question has been asked many times, but I am fairly new at Mathematica and the other answers are very complex, and certainly too complicated for this simple code I am trying to write. ...
1
vote
2answers
167 views

Weird behaviour of HoldPattern

I'm still thinking about how to implement Condition with anonymous patterns. And now I think I've found a way to implement it, but again, a suspected unclear ...
6
votes
2answers
233 views

Why the pattern match don't work as expected

When I try to figure out this problem,I write such code: ...
8
votes
1answer
482 views

Why does pattern test work only with pure functions?

Why is it that pattern test works only with pure functions? Cases[Range[0, 70], _?(Divisible[#, 7] &)] Cases[Range[0, 70], x_?(Divisible[x, 7])] I ...
4
votes
1answer
275 views

Why is there a difference when formulating patterns for Select and FirstPosition?

Select[{1, 2, 4, 7, 6, 2}, # > 2 &] Gives {4, 7, 6}. OK! So one should think that the following would work: ...
2
votes
2answers
86 views

Evaluation speed of apparently equivalent functions

Consider the following expressions: f[x_Integer] := x, f[x_] := x /; x ∈ Integers, f[x_?IntegerQ] := x All of the expressions above (and probably others which ...
0
votes
2answers
2k views

Function with condition

I am starting my adventure with Mathematica. I would like to know if is there possibility to create function described by formula for example f(x):=1+2^n where 2^n < x. I have problem with this ...
2
votes
2answers
197 views

Can a pattern examine all partitions of a sequence?

Say I have a list: {a, b, c, d}. I'd like to check that the list has some partition, say {{a, b, c}, {d}} such that all the elements of the partition satisfy a ...
1
vote
3answers
278 views

IntegerQ returning False despite setting Assumptions

Why does the following not return True? Assuming[z ∈ Integers, IntegerQ[z]] False I tried this on a fresh session of ...
17
votes
5answers
3k views

Implement the Bisection algorithm elegantly and easily

Description: Rencently, I have finished my course Numerical Analysis, so I'd like to implement many algorithm that I have learned from that course.By this practice, I hope that I can improve my ...
0
votes
0answers
61 views

How to correctly use PatternTest (?) [duplicate]

This works fine: {3, -5, 2, 7, -6, 3} /. x_ /; x < 0 :> 0 (*{3, 0, 2, 7, 0, 3}*) and this works fine: ...
5
votes
1answer
231 views

Multiple down-values with exactly the same lefthand side

I was working on an answer to this question, when I was sidetracked by what I bring up here. I wanted a function, which when given a string representing a binary number, would convert the string to a ...

15 30 50 per page