
(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 (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 98.4%
mul-1-neg98.4%
+-commutative98.4%
distribute-rgt-neg-out98.4%
+-commutative98.4%
Simplified98.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.8%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -27.5) (not (<= z 2.1e-7))) (- x (* x z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -27.5) || !(z <= 2.1e-7)) {
tmp = x - (x * z);
} 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 <= (-27.5d0)) .or. (.not. (z <= 2.1d-7))) then
tmp = x - (x * z)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -27.5) || !(z <= 2.1e-7)) {
tmp = x - (x * z);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -27.5) or not (z <= 2.1e-7): tmp = x - (x * z) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -27.5) || !(z <= 2.1e-7)) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -27.5) || ~((z <= 2.1e-7))) tmp = x - (x * z); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -27.5], N[Not[LessEqual[z, 2.1e-7]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -27.5 \lor \neg \left(z \leq 2.1 \cdot 10^{-7}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -27.5 or 2.1e-7 < z Initial program 100.0%
Taylor expanded in x around inf 57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt1-in57.3%
distribute-lft-neg-out57.3%
unsub-neg57.3%
Simplified57.3%
if -27.5 < z < 2.1e-7Initial program 100.0%
Taylor expanded in z around 0 98.2%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -410000000.0) (not (<= z 1.0))) (* z (- y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -410000000.0) || !(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 <= (-410000000.0d0)) .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 <= -410000000.0) || !(z <= 1.0)) {
tmp = z * -y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -410000000.0) or not (z <= 1.0): tmp = z * -y else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -410000000.0) || !(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 <= -410000000.0) || ~((z <= 1.0))) tmp = z * -y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -410000000.0], 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 -410000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -4.1e8 or 1 < z Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in93.1%
Applied egg-rr93.1%
Taylor expanded in z around inf 92.9%
associate-*r*92.9%
neg-mul-192.9%
Simplified92.9%
Taylor expanded in y around inf 48.8%
associate-*r*48.8%
mul-1-neg48.8%
Simplified48.8%
if -4.1e8 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.0%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (<= z -410000000.0) (* z (- y)) (if (<= z 1.0) (+ x y) (* z (- x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -410000000.0) {
tmp = z * -y;
} else if (z <= 1.0) {
tmp = x + y;
} else {
tmp = z * -x;
}
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 <= (-410000000.0d0)) then
tmp = z * -y
else if (z <= 1.0d0) then
tmp = x + y
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -410000000.0) {
tmp = z * -y;
} else if (z <= 1.0) {
tmp = x + y;
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -410000000.0: tmp = z * -y elif z <= 1.0: tmp = x + y else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -410000000.0) tmp = Float64(z * Float64(-y)); elseif (z <= 1.0) tmp = Float64(x + y); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -410000000.0) tmp = z * -y; elseif (z <= 1.0) tmp = x + y; else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -410000000.0], N[(z * (-y)), $MachinePrecision], If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -410000000:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if z < -4.1e8Initial program 100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in93.0%
Applied egg-rr93.0%
Taylor expanded in z around inf 93.0%
associate-*r*93.0%
neg-mul-193.0%
Simplified93.0%
Taylor expanded in y around inf 54.4%
associate-*r*54.4%
mul-1-neg54.4%
Simplified54.4%
if -4.1e8 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.0%
if 1 < z Initial program 99.9%
Taylor expanded in z around inf 99.5%
mul-1-neg99.5%
+-commutative99.5%
distribute-rgt-neg-out99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in y around 0 61.1%
associate-*r*61.1%
mul-1-neg61.1%
Simplified61.1%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.1e-59) (- x (* x z)) (- y (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e-59) {
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 <= (-1.1d-59)) 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 <= -1.1e-59) {
tmp = x - (x * z);
} else {
tmp = y - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e-59: tmp = x - (x * z) else: tmp = y - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e-59) 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 <= -1.1e-59) tmp = x - (x * z); else tmp = y - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e-59], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-59}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot z\\
\end{array}
\end{array}
if x < -1.0999999999999999e-59Initial program 100.0%
Taylor expanded in x around inf 80.2%
sub-neg80.2%
+-commutative80.2%
distribute-rgt1-in80.2%
distribute-lft-neg-out80.2%
unsub-neg80.2%
Simplified80.2%
if -1.0999999999999999e-59 < x Initial program 100.0%
Taylor expanded in x around 0 57.2%
sub-neg57.2%
distribute-lft-in57.2%
distribute-rgt-neg-out57.2%
unsub-neg57.2%
*-rgt-identity57.2%
Simplified57.2%
Final simplification63.8%
(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 54.5%
Final simplification54.5%
(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%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in96.9%
Applied egg-rr96.9%
Taylor expanded in z around inf 71.1%
associate-*r*71.1%
neg-mul-171.1%
Simplified71.1%
Taylor expanded in z around 0 29.0%
Final simplification29.0%
herbie shell --seed 2023279
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))