
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
(FPCore (x y z) :precision binary64 (* (+ z 1.0) (+ x y)))
double code(double x, double y, double z) {
return (z + 1.0) * (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 = (z + 1.0d0) * (x + y)
end function
public static double code(double x, double y, double z) {
return (z + 1.0) * (x + y);
}
def code(x, y, z): return (z + 1.0) * (x + y)
function code(x, y, z) return Float64(Float64(z + 1.0) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (z + 1.0) * (x + y); end
code[x_, y_, z_] := N[(N[(z + 1.0), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(z + 1\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= (+ z 1.0) -5.0) (* x z) (if (<= (+ z 1.0) 2.0) (+ x y) (if (<= (+ z 1.0) 2e+111) (* y z) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -5.0) {
tmp = x * z;
} else if ((z + 1.0) <= 2.0) {
tmp = x + y;
} else if ((z + 1.0) <= 2e+111) {
tmp = y * z;
} else {
tmp = x * 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 ((z + 1.0d0) <= (-5.0d0)) then
tmp = x * z
else if ((z + 1.0d0) <= 2.0d0) then
tmp = x + y
else if ((z + 1.0d0) <= 2d+111) then
tmp = y * z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -5.0) {
tmp = x * z;
} else if ((z + 1.0) <= 2.0) {
tmp = x + y;
} else if ((z + 1.0) <= 2e+111) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -5.0: tmp = x * z elif (z + 1.0) <= 2.0: tmp = x + y elif (z + 1.0) <= 2e+111: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -5.0) tmp = Float64(x * z); elseif (Float64(z + 1.0) <= 2.0) tmp = Float64(x + y); elseif (Float64(z + 1.0) <= 2e+111) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + 1.0) <= -5.0) tmp = x * z; elseif ((z + 1.0) <= 2.0) tmp = x + y; elseif ((z + 1.0) <= 2e+111) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -5.0], N[(x * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 2.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 2e+111], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z + 1 \leq 2:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z + 1 \leq 2 \cdot 10^{+111}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -5 or 1.99999999999999991e111 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
accelerator-lowering-fma.f6451.3
Simplified51.3%
Taylor expanded in z around inf
*-lowering-*.f6450.9
Simplified50.9%
if -5 < (+.f64 z #s(literal 1 binary64)) < 2Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6498.0
Simplified98.0%
if 2 < (+.f64 z #s(literal 1 binary64)) < 1.99999999999999991e111Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f6451.5
Simplified51.5%
Taylor expanded in z around inf
*-lowering-*.f6449.9
Simplified49.9%
Final simplification73.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e+258) (+ x y) (if (<= (+ x y) -2e-245) (* x z) (fma y z y))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e+258) {
tmp = x + y;
} else if ((x + y) <= -2e-245) {
tmp = x * z;
} else {
tmp = fma(y, z, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e+258) tmp = Float64(x + y); elseif (Float64(x + y) <= -2e-245) tmp = Float64(x * z); else tmp = fma(y, z, y); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e+258], N[(x + y), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], -2e-245], N[(x * z), $MachinePrecision], N[(y * z + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{+258}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;x + y \leq -2 \cdot 10^{-245}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, z, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.00000000000000006e258Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6471.9
Simplified71.9%
if -1.00000000000000006e258 < (+.f64 x y) < -1.9999999999999999e-245Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
accelerator-lowering-fma.f6444.5
Simplified44.5%
Taylor expanded in z around inf
*-lowering-*.f6425.7
Simplified25.7%
if -1.9999999999999999e-245 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f6454.2
Simplified54.2%
Final simplification45.3%
(FPCore (x y z) :precision binary64 (if (<= (+ z 1.0) -5.0) (* x z) (if (<= (+ z 1.0) 1000.0) (+ x y) (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -5.0) {
tmp = x * z;
} else if ((z + 1.0) <= 1000.0) {
tmp = x + y;
} else {
tmp = x * 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 ((z + 1.0d0) <= (-5.0d0)) then
tmp = x * z
else if ((z + 1.0d0) <= 1000.0d0) then
tmp = x + y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -5.0) {
tmp = x * z;
} else if ((z + 1.0) <= 1000.0) {
tmp = x + y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -5.0: tmp = x * z elif (z + 1.0) <= 1000.0: tmp = x + y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -5.0) tmp = Float64(x * z); elseif (Float64(z + 1.0) <= 1000.0) tmp = Float64(x + y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + 1.0) <= -5.0) tmp = x * z; elseif ((z + 1.0) <= 1000.0) tmp = x + y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -5.0], N[(x * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 1000.0], N[(x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z + 1 \leq 1000:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -5 or 1e3 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
accelerator-lowering-fma.f6450.8
Simplified50.8%
Taylor expanded in z around inf
*-lowering-*.f6449.9
Simplified49.9%
if -5 < (+.f64 z #s(literal 1 binary64)) < 1e3Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6497.3
Simplified97.3%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (if (<= (* (+ z 1.0) (+ x y)) -1e-196) x y))
double code(double x, double y, double z) {
double tmp;
if (((z + 1.0) * (x + y)) <= -1e-196) {
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 (((z + 1.0d0) * (x + y)) <= (-1d-196)) 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 (((z + 1.0) * (x + y)) <= -1e-196) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((z + 1.0) * (x + y)) <= -1e-196: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(z + 1.0) * Float64(x + y)) <= -1e-196) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((z + 1.0) * (x + y)) <= -1e-196) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(z + 1.0), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision], -1e-196], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(z + 1\right) \cdot \left(x + y\right) \leq -1 \cdot 10^{-196}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (+.f64 z #s(literal 1 binary64))) < -1e-196Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6446.2
Simplified46.2%
Taylor expanded in y around 0
Simplified23.3%
if -1e-196 < (*.f64 (+.f64 x y) (+.f64 z #s(literal 1 binary64))) Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6451.1
Simplified51.1%
Taylor expanded in y around inf
Simplified30.7%
Final simplification27.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-245) (fma z x x) (fma y z y)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-245) {
tmp = fma(z, x, x);
} else {
tmp = fma(y, z, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-245) tmp = fma(z, x, x); else tmp = fma(y, z, y); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-245], N[(z * x + x), $MachinePrecision], N[(y * z + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-245}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, z, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.9999999999999999e-245Initial program 99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
accelerator-lowering-fma.f6445.9
Simplified45.9%
if -1.9999999999999999e-245 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f6454.2
Simplified54.2%
(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
+-commutativeN/A
+-lowering-+.f6448.8
Simplified48.8%
Final simplification48.8%
(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 z around 0
+-commutativeN/A
+-lowering-+.f6448.8
Simplified48.8%
Taylor expanded in y around 0
Simplified21.8%
herbie shell --seed 2024205
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))