
(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 8 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}
(FPCore (x y z) :precision binary64 (* (- 1.0 z) (+ x y)))
double code(double x, double y, double z) {
return (1.0 - z) * (x + y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 - z) * (x + y)
end function
public static double code(double x, double y, double z) {
return (1.0 - z) * (x + y);
}
def code(x, y, z): return (1.0 - z) * (x + y)
function code(x, y, z) return Float64(Float64(1.0 - z) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (1.0 - z) * (x + y); end
code[x_, y_, z_] := N[(N[(1.0 - z), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - z\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= z -4.4e+243)
(* z (- x))
(if (<= z -195000000000.0)
t_0
(if (<= z 7.3e-9)
(+ x y)
(if (or (<= z 1.4e+25) (not (<= z 6.2e+236))) (- x (* x z)) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -4.4e+243) {
tmp = z * -x;
} else if (z <= -195000000000.0) {
tmp = t_0;
} else if (z <= 7.3e-9) {
tmp = x + y;
} else if ((z <= 1.4e+25) || !(z <= 6.2e+236)) {
tmp = x - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
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 = y * -z
if (z <= (-4.4d+243)) then
tmp = z * -x
else if (z <= (-195000000000.0d0)) then
tmp = t_0
else if (z <= 7.3d-9) then
tmp = x + y
else if ((z <= 1.4d+25) .or. (.not. (z <= 6.2d+236))) then
tmp = x - (x * z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -4.4e+243) {
tmp = z * -x;
} else if (z <= -195000000000.0) {
tmp = t_0;
} else if (z <= 7.3e-9) {
tmp = x + y;
} else if ((z <= 1.4e+25) || !(z <= 6.2e+236)) {
tmp = x - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if z <= -4.4e+243: tmp = z * -x elif z <= -195000000000.0: tmp = t_0 elif z <= 7.3e-9: tmp = x + y elif (z <= 1.4e+25) or not (z <= 6.2e+236): tmp = x - (x * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (z <= -4.4e+243) tmp = Float64(z * Float64(-x)); elseif (z <= -195000000000.0) tmp = t_0; elseif (z <= 7.3e-9) tmp = Float64(x + y); elseif ((z <= 1.4e+25) || !(z <= 6.2e+236)) tmp = Float64(x - Float64(x * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (z <= -4.4e+243) tmp = z * -x; elseif (z <= -195000000000.0) tmp = t_0; elseif (z <= 7.3e-9) tmp = x + y; elseif ((z <= 1.4e+25) || ~((z <= 6.2e+236))) tmp = x - (x * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -4.4e+243], N[(z * (-x)), $MachinePrecision], If[LessEqual[z, -195000000000.0], t$95$0, If[LessEqual[z, 7.3e-9], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.4e+25], N[Not[LessEqual[z, 6.2e+236]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -4.4 \cdot 10^{+243}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq -195000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 7.3 \cdot 10^{-9}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+25} \lor \neg \left(z \leq 6.2 \cdot 10^{+236}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -4.40000000000000018e243Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in91.7%
Applied egg-rr91.7%
Taylor expanded in z around inf 91.7%
associate-*r*91.7%
mul-1-neg91.7%
Simplified91.7%
Taylor expanded in y around 0 83.4%
mul-1-neg83.4%
distribute-rgt-neg-in83.4%
Simplified83.4%
if -4.40000000000000018e243 < z < -1.95e11 or 1.4000000000000001e25 < z < 6.19999999999999999e236Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in98.9%
Applied egg-rr98.9%
Taylor expanded in z around inf 98.9%
associate-*r*98.9%
mul-1-neg98.9%
Simplified98.9%
Taylor expanded in z around inf 98.9%
associate-*r*98.9%
neg-mul-198.9%
Simplified98.9%
Taylor expanded in y around inf 53.2%
associate-*r*53.2%
mul-1-neg53.2%
Simplified53.2%
if -1.95e11 < z < 7.30000000000000002e-9Initial program 100.0%
Taylor expanded in z around 0 98.0%
if 7.30000000000000002e-9 < z < 1.4000000000000001e25 or 6.19999999999999999e236 < z Initial program 100.0%
Taylor expanded in x around inf 49.4%
sub-neg49.4%
+-commutative49.4%
distribute-rgt1-in49.4%
distribute-lft-neg-out49.4%
unsub-neg49.4%
Simplified49.4%
Final simplification77.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))) (t_1 (* y (- z))))
(if (<= z -6.8e+246)
t_0
(if (<= z -195000000000.0)
t_1
(if (<= z 1.0) (+ x y) (if (<= z 7.5e+236) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double t_1 = y * -z;
double tmp;
if (z <= -6.8e+246) {
tmp = t_0;
} else if (z <= -195000000000.0) {
tmp = t_1;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 7.5e+236) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
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) :: t_1
real(8) :: tmp
t_0 = z * -x
t_1 = y * -z
if (z <= (-6.8d+246)) then
tmp = t_0
else if (z <= (-195000000000.0d0)) then
tmp = t_1
else if (z <= 1.0d0) then
tmp = x + y
else if (z <= 7.5d+236) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double t_1 = y * -z;
double tmp;
if (z <= -6.8e+246) {
tmp = t_0;
} else if (z <= -195000000000.0) {
tmp = t_1;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 7.5e+236) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x t_1 = y * -z tmp = 0 if z <= -6.8e+246: tmp = t_0 elif z <= -195000000000.0: tmp = t_1 elif z <= 1.0: tmp = x + y elif z <= 7.5e+236: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) t_1 = Float64(y * Float64(-z)) tmp = 0.0 if (z <= -6.8e+246) tmp = t_0; elseif (z <= -195000000000.0) tmp = t_1; elseif (z <= 1.0) tmp = Float64(x + y); elseif (z <= 7.5e+236) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; t_1 = y * -z; tmp = 0.0; if (z <= -6.8e+246) tmp = t_0; elseif (z <= -195000000000.0) tmp = t_1; elseif (z <= 1.0) tmp = x + y; elseif (z <= 7.5e+236) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, Block[{t$95$1 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -6.8e+246], t$95$0, If[LessEqual[z, -195000000000.0], t$95$1, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 7.5e+236], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
t_1 := y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -6.8 \cdot 10^{+246}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -195000000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{+236}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -6.79999999999999977e246 or 7.5e236 < z Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in89.3%
Applied egg-rr89.3%
Taylor expanded in z around inf 89.3%
associate-*r*89.3%
mul-1-neg89.3%
Simplified89.3%
Taylor expanded in y around 0 65.3%
mul-1-neg65.3%
distribute-rgt-neg-in65.3%
Simplified65.3%
if -6.79999999999999977e246 < z < -1.95e11 or 1 < z < 7.5e236Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in98.9%
Applied egg-rr98.9%
Taylor expanded in z around inf 98.9%
associate-*r*98.9%
mul-1-neg98.9%
Simplified98.9%
Taylor expanded in z around inf 98.3%
associate-*r*98.3%
neg-mul-198.3%
Simplified98.3%
Taylor expanded in y around inf 53.5%
associate-*r*53.5%
mul-1-neg53.5%
Simplified53.5%
if -1.95e11 < z < 1Initial program 100.0%
Taylor expanded in z around 0 96.9%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (- (- y) x)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (-y - x);
} else {
tmp = x + y;
}
return tmp;
}
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 ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * (-y - x)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (-y - x);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = z * (-y - x) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(z * Float64(Float64(-y) - x)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = z * (-y - x); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[((-y) - x), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(\left(-y\right) - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 99.1%
mul-1-neg99.1%
+-commutative99.1%
distribute-rgt-neg-out99.1%
+-commutative99.1%
Simplified99.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.2%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -280.0) (not (<= z 1.0))) (* z (- x)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -280.0) || !(z <= 1.0)) {
tmp = z * -x;
} else {
tmp = x + y;
}
return tmp;
}
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 ((z <= (-280.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * -x
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -280.0) || !(z <= 1.0)) {
tmp = z * -x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -280.0) or not (z <= 1.0): tmp = z * -x else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -280.0) || !(z <= 1.0)) tmp = Float64(z * Float64(-x)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -280.0) || ~((z <= 1.0))) tmp = z * -x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -280.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -280 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -280 or 1 < z Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in96.7%
Applied egg-rr96.7%
Taylor expanded in z around inf 96.7%
associate-*r*96.7%
mul-1-neg96.7%
Simplified96.7%
Taylor expanded in y around 0 53.9%
mul-1-neg53.9%
distribute-rgt-neg-in53.9%
Simplified53.9%
if -280 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.2%
Final simplification76.9%
(FPCore (x y z) :precision binary64 (if (<= x -3.2e-34) (- x (* x z)) (- y (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e-34) {
tmp = x - (x * z);
} else {
tmp = y - (y * z);
}
return tmp;
}
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 <= (-3.2d-34)) then
tmp = x - (x * z)
else
tmp = y - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e-34) {
tmp = x - (x * z);
} else {
tmp = y - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.2e-34: tmp = x - (x * z) else: tmp = y - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.2e-34) tmp = Float64(x - Float64(x * z)); else tmp = Float64(y - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.2e-34) tmp = x - (x * z); else tmp = y - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.2e-34], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-34}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot z\\
\end{array}
\end{array}
if x < -3.20000000000000003e-34Initial program 100.0%
Taylor expanded in x around inf 74.1%
sub-neg74.1%
+-commutative74.1%
distribute-rgt1-in74.1%
distribute-lft-neg-out74.1%
unsub-neg74.1%
Simplified74.1%
if -3.20000000000000003e-34 < x Initial program 100.0%
Taylor expanded in x around 0 64.2%
sub-neg64.2%
distribute-lft-in64.2%
distribute-rgt-neg-out64.2%
unsub-neg64.2%
*-rgt-identity64.2%
Simplified64.2%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (+ x y))
double code(double x, double y, double z) {
return x + y;
}
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
end function
public static double code(double x, double y, double z) {
return x + y;
}
def code(x, y, z): return x + y
function code(x, y, z) return Float64(x + y) end
function tmp = code(x, y, z) tmp = x + y; end
code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 52.6%
Final simplification52.6%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in98.4%
Applied egg-rr98.4%
Taylor expanded in z around inf 75.7%
associate-*r*75.7%
mul-1-neg75.7%
Simplified75.7%
Taylor expanded in z around 0 30.0%
Final simplification30.0%
herbie shell --seed 2023278
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))