
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma (- 1.0 z) y (* (- 1.0 z) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma((1.0 - z), y, ((1.0 - z) * x));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(Float64(1.0 - z), y, Float64(Float64(1.0 - z) * x)) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(1.0 - z), $MachinePrecision] * y + N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(1 - z, y, \left(1 - z\right) \cdot x\right)
\end{array}
Initial program 100.0%
Applied rewrites99.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= (- 1.0 z) -5e+104)
t_0
(if (<= (- 1.0 z) -100.0)
(* (- z) y)
(if (<= (- 1.0 z) 400000000.0) (+ y x) t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if ((1.0 - z) <= -5e+104) {
tmp = t_0;
} else if ((1.0 - z) <= -100.0) {
tmp = -z * y;
} else if ((1.0 - z) <= 400000000.0) {
tmp = y + x;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = -z * x
if ((1.0d0 - z) <= (-5d+104)) then
tmp = t_0
else if ((1.0d0 - z) <= (-100.0d0)) then
tmp = -z * y
else if ((1.0d0 - z) <= 400000000.0d0) then
tmp = y + x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if ((1.0 - z) <= -5e+104) {
tmp = t_0;
} else if ((1.0 - z) <= -100.0) {
tmp = -z * y;
} else if ((1.0 - z) <= 400000000.0) {
tmp = y + x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -z * x tmp = 0 if (1.0 - z) <= -5e+104: tmp = t_0 elif (1.0 - z) <= -100.0: tmp = -z * y elif (1.0 - z) <= 400000000.0: tmp = y + x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (Float64(1.0 - z) <= -5e+104) tmp = t_0; elseif (Float64(1.0 - z) <= -100.0) tmp = Float64(Float64(-z) * y); elseif (Float64(1.0 - z) <= 400000000.0) tmp = Float64(y + x); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = -z * x;
tmp = 0.0;
if ((1.0 - z) <= -5e+104)
tmp = t_0;
elseif ((1.0 - z) <= -100.0)
tmp = -z * y;
elseif ((1.0 - z) <= 400000000.0)
tmp = y + x;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[N[(1.0 - z), $MachinePrecision], -5e+104], t$95$0, If[LessEqual[N[(1.0 - z), $MachinePrecision], -100.0], N[((-z) * y), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 400000000.0], N[(y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;1 - z \leq -5 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - z \leq -100:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{elif}\;1 - z \leq 400000000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -4.9999999999999997e104 or 4e8 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6453.8
Applied rewrites53.8%
Taylor expanded in z around inf
Applied rewrites53.8%
if -4.9999999999999997e104 < (-.f64 #s(literal 1 binary64) z) < -100Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.5
Applied rewrites49.5%
Taylor expanded in z around inf
Applied rewrites44.8%
if -100 < (-.f64 #s(literal 1 binary64) z) < 4e8Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.4
Applied rewrites52.4%
Taylor expanded in z around inf
Applied rewrites52.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.0
Applied rewrites97.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= z -240000000.0)
t_0
(if (<= z 2.5e-9)
(+ y x)
(if (<= z 3.5e+49)
(* (- 1.0 z) x)
(if (<= z 4.8e+100) (* (- z) y) t_0))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -240000000.0) {
tmp = t_0;
} else if (z <= 2.5e-9) {
tmp = y + x;
} else if (z <= 3.5e+49) {
tmp = (1.0 - z) * x;
} else if (z <= 4.8e+100) {
tmp = -z * y;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = -z * x
if (z <= (-240000000.0d0)) then
tmp = t_0
else if (z <= 2.5d-9) then
tmp = y + x
else if (z <= 3.5d+49) then
tmp = (1.0d0 - z) * x
else if (z <= 4.8d+100) then
tmp = -z * y
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -240000000.0) {
tmp = t_0;
} else if (z <= 2.5e-9) {
tmp = y + x;
} else if (z <= 3.5e+49) {
tmp = (1.0 - z) * x;
} else if (z <= 4.8e+100) {
tmp = -z * y;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -z * x tmp = 0 if z <= -240000000.0: tmp = t_0 elif z <= 2.5e-9: tmp = y + x elif z <= 3.5e+49: tmp = (1.0 - z) * x elif z <= 4.8e+100: tmp = -z * y else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (z <= -240000000.0) tmp = t_0; elseif (z <= 2.5e-9) tmp = Float64(y + x); elseif (z <= 3.5e+49) tmp = Float64(Float64(1.0 - z) * x); elseif (z <= 4.8e+100) tmp = Float64(Float64(-z) * y); else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = -z * x;
tmp = 0.0;
if (z <= -240000000.0)
tmp = t_0;
elseif (z <= 2.5e-9)
tmp = y + x;
elseif (z <= 3.5e+49)
tmp = (1.0 - z) * x;
elseif (z <= 4.8e+100)
tmp = -z * y;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[z, -240000000.0], t$95$0, If[LessEqual[z, 2.5e-9], N[(y + x), $MachinePrecision], If[LessEqual[z, 3.5e+49], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[z, 4.8e+100], N[((-z) * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;z \leq -240000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-9}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+49}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.4e8 or 4.80000000000000023e100 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6453.8
Applied rewrites53.8%
Taylor expanded in z around inf
Applied rewrites53.8%
if -2.4e8 < z < 2.5000000000000001e-9Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.1
Applied rewrites52.1%
Taylor expanded in z around inf
Applied rewrites51.9%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.5
Applied rewrites97.5%
if 2.5000000000000001e-9 < z < 3.49999999999999975e49Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.0
Applied rewrites52.0%
if 3.49999999999999975e49 < z < 4.80000000000000023e100Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6443.6
Applied rewrites43.6%
Taylor expanded in z around inf
Applied rewrites43.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -100.0) (not (<= (- 1.0 z) 400000000.0))) (* (- z) x) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -100.0) || !((1.0 - z) <= 400000000.0)) {
tmp = -z * x;
} else {
tmp = y + x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((1.0d0 - z) <= (-100.0d0)) .or. (.not. ((1.0d0 - z) <= 400000000.0d0))) then
tmp = -z * x
else
tmp = y + x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -100.0) || !((1.0 - z) <= 400000000.0)) {
tmp = -z * x;
} else {
tmp = y + x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((1.0 - z) <= -100.0) or not ((1.0 - z) <= 400000000.0): tmp = -z * x else: tmp = y + x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(1.0 - z) <= -100.0) || !(Float64(1.0 - z) <= 400000000.0)) tmp = Float64(Float64(-z) * x); else tmp = Float64(y + x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((1.0 - z) <= -100.0) || ~(((1.0 - z) <= 400000000.0)))
tmp = -z * x;
else
tmp = y + x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -100.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 400000000.0]], $MachinePrecision]], N[((-z) * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -100 \lor \neg \left(1 - z \leq 400000000\right):\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -100 or 4e8 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6453.9
Applied rewrites53.9%
Taylor expanded in z around inf
Applied rewrites53.3%
if -100 < (-.f64 #s(literal 1 binary64) z) < 4e8Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.4
Applied rewrites52.4%
Taylor expanded in z around inf
Applied rewrites52.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.0
Applied rewrites97.0%
Final simplification76.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -4e-285) (* (- 1.0 z) x) (* (- 1.0 z) y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -4e-285) {
tmp = (1.0 - z) * x;
} else {
tmp = (1.0 - z) * y;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x + y) <= (-4d-285)) then
tmp = (1.0d0 - z) * x
else
tmp = (1.0d0 - z) * y
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -4e-285) {
tmp = (1.0 - z) * x;
} else {
tmp = (1.0 - z) * y;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (x + y) <= -4e-285: tmp = (1.0 - z) * x else: tmp = (1.0 - z) * y return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -4e-285) tmp = Float64(Float64(1.0 - z) * x); else tmp = Float64(Float64(1.0 - z) * y); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x + y) <= -4e-285)
tmp = (1.0 - z) * x;
else
tmp = (1.0 - z) * y;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -4e-285], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -4 \cdot 10^{-285}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot y\\
\end{array}
\end{array}
if (+.f64 x y) < -4.0000000000000003e-285Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6454.3
Applied rewrites54.3%
if -4.0000000000000003e-285 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6452.4
Applied rewrites52.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (1.0d0 - z)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x + y) * (1.0 - z)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x + y) * (1.0 - z);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Initial program 100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ y x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y + x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y + x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y + x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y + x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y + x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y + x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6453.1
Applied rewrites53.1%
Taylor expanded in z around inf
Applied rewrites53.1%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6452.3
Applied rewrites52.3%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))