
(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}
(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 (if (or (<= (- 1.0 z) -1.0) (not (<= (- 1.0 z) 2.0))) (* z (- (- y) x)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -1.0) || !((1.0 - z) <= 2.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 (((1.0d0 - z) <= (-1.0d0)) .or. (.not. ((1.0d0 - z) <= 2.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 (((1.0 - z) <= -1.0) || !((1.0 - z) <= 2.0)) {
tmp = z * (-y - x);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((1.0 - z) <= -1.0) or not ((1.0 - z) <= 2.0): tmp = z * (-y - x) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(1.0 - z) <= -1.0) || !(Float64(1.0 - z) <= 2.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 (((1.0 - z) <= -1.0) || ~(((1.0 - z) <= 2.0))) tmp = z * (-y - x); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -1.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0]], $MachinePrecision]], N[(z * N[((-y) - x), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -1 \lor \neg \left(1 - z \leq 2\right):\\
\;\;\;\;z \cdot \left(\left(-y\right) - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (-.f64 1 z) < -1 or 2 < (-.f64 1 z) Initial program 100.0%
Taylor expanded in z around inf 97.6%
mul-1-neg97.6%
+-commutative97.6%
distribute-rgt-neg-out97.6%
+-commutative97.6%
Simplified97.6%
if -1 < (-.f64 1 z) < 2Initial program 100.0%
Taylor expanded in z around 0 98.6%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e+28) (- x (* x z)) (if (or (<= x -12.8) (not (<= x -7.2e-41))) (- y (* y z)) (* x (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+28) {
tmp = x - (x * z);
} else if ((x <= -12.8) || !(x <= -7.2e-41)) {
tmp = y - (y * z);
} else {
tmp = x * (1.0 - 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 <= (-4.2d+28)) then
tmp = x - (x * z)
else if ((x <= (-12.8d0)) .or. (.not. (x <= (-7.2d-41)))) then
tmp = y - (y * z)
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+28) {
tmp = x - (x * z);
} else if ((x <= -12.8) || !(x <= -7.2e-41)) {
tmp = y - (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.2e+28: tmp = x - (x * z) elif (x <= -12.8) or not (x <= -7.2e-41): tmp = y - (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.2e+28) tmp = Float64(x - Float64(x * z)); elseif ((x <= -12.8) || !(x <= -7.2e-41)) tmp = Float64(y - Float64(y * z)); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.2e+28) tmp = x - (x * z); elseif ((x <= -12.8) || ~((x <= -7.2e-41))) tmp = y - (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.2e+28], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -12.8], N[Not[LessEqual[x, -7.2e-41]], $MachinePrecision]], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+28}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;x \leq -12.8 \lor \neg \left(x \leq -7.2 \cdot 10^{-41}\right):\\
\;\;\;\;y - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if x < -4.19999999999999978e28Initial program 99.9%
Taylor expanded in x around inf 80.6%
sub-neg80.6%
+-commutative80.6%
distribute-rgt1-in80.6%
distribute-lft-neg-out80.6%
unsub-neg80.6%
Simplified80.6%
if -4.19999999999999978e28 < x < -12.800000000000001 or -7.2e-41 < x Initial program 100.0%
Taylor expanded in x around 0 58.8%
sub-neg58.8%
distribute-lft-in58.8%
distribute-rgt-neg-out58.8%
unsub-neg58.8%
*-rgt-identity58.8%
Simplified58.8%
if -12.800000000000001 < x < -7.2e-41Initial program 100.0%
Taylor expanded in x around inf 71.7%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -26.5) (not (<= z 1.0))) (* z (- y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -26.5) || !(z <= 1.0)) {
tmp = z * -y;
} 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 <= (-26.5d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * -y
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -26.5) || !(z <= 1.0)) {
tmp = z * -y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -26.5) or not (z <= 1.0): tmp = z * -y else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -26.5) || !(z <= 1.0)) tmp = Float64(z * Float64(-y)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -26.5) || ~((z <= 1.0))) tmp = z * -y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -26.5], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * (-y)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -26.5 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -26.5 or 1 < z Initial program 100.0%
Taylor expanded in x around 0 49.2%
sub-neg49.2%
distribute-lft-in49.2%
distribute-rgt-neg-out49.2%
unsub-neg49.2%
*-rgt-identity49.2%
Simplified49.2%
Taylor expanded in z around inf 48.0%
associate-*r*48.0%
neg-mul-148.0%
Simplified48.0%
if -26.5 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.6%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (<= x -9.2e-97) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.2e-97) {
tmp = x;
} else {
tmp = 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 (x <= (-9.2d-97)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -9.2e-97) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.2e-97: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.2e-97) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.2e-97) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.2e-97], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{-97}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -9.19999999999999976e-97Initial program 100.0%
Taylor expanded in x around inf 68.1%
Taylor expanded in z around 0 35.4%
if -9.19999999999999976e-97 < x Initial program 100.0%
Taylor expanded in x around 0 57.0%
sub-neg57.0%
distribute-lft-in57.0%
distribute-rgt-neg-out57.0%
unsub-neg57.0%
*-rgt-identity57.0%
Simplified57.0%
Taylor expanded in z around 0 33.2%
Final simplification33.9%
(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 53.3%
Final simplification53.3%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 52.3%
Taylor expanded in z around 0 26.0%
Final simplification26.0%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))