
(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 (<= y 1.24e-132)
(* x (- 1.0 z))
(if (or (<= y 1.45e-74) (and (not (<= y 5e-13)) (<= y 2.8e+21)))
(+ x y)
(* y (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.24e-132) {
tmp = x * (1.0 - z);
} else if ((y <= 1.45e-74) || (!(y <= 5e-13) && (y <= 2.8e+21))) {
tmp = x + y;
} else {
tmp = y * (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 (y <= 1.24d-132) then
tmp = x * (1.0d0 - z)
else if ((y <= 1.45d-74) .or. (.not. (y <= 5d-13)) .and. (y <= 2.8d+21)) then
tmp = x + y
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.24e-132) {
tmp = x * (1.0 - z);
} else if ((y <= 1.45e-74) || (!(y <= 5e-13) && (y <= 2.8e+21))) {
tmp = x + y;
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.24e-132: tmp = x * (1.0 - z) elif (y <= 1.45e-74) or (not (y <= 5e-13) and (y <= 2.8e+21)): tmp = x + y else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.24e-132) tmp = Float64(x * Float64(1.0 - z)); elseif ((y <= 1.45e-74) || (!(y <= 5e-13) && (y <= 2.8e+21))) tmp = Float64(x + y); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.24e-132) tmp = x * (1.0 - z); elseif ((y <= 1.45e-74) || (~((y <= 5e-13)) && (y <= 2.8e+21))) tmp = x + y; else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.24e-132], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.45e-74], And[N[Not[LessEqual[y, 5e-13]], $MachinePrecision], LessEqual[y, 2.8e+21]]], N[(x + y), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.24 \cdot 10^{-132}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-74} \lor \neg \left(y \leq 5 \cdot 10^{-13}\right) \land y \leq 2.8 \cdot 10^{+21}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < 1.24000000000000006e-132Initial program 100.0%
Taylor expanded in x around inf 55.9%
*-commutative55.9%
Simplified55.9%
if 1.24000000000000006e-132 < y < 1.45e-74 or 4.9999999999999999e-13 < y < 2.8e21Initial program 100.0%
Taylor expanded in z around 0 73.6%
+-commutative73.6%
Simplified73.6%
if 1.45e-74 < y < 4.9999999999999999e-13 or 2.8e21 < y Initial program 100.0%
Taylor expanded in x around 0 75.1%
Final simplification62.8%
(FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -20000.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) <= -20000.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) <= (-20000.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) <= -20000.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) <= -20000.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) <= -20000.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) <= -20000.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], -20000.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 -20000 \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) < -2e4 or 2 < (-.f64 1 z) Initial program 100.0%
Taylor expanded in z around inf 98.5%
associate-*r*98.5%
neg-mul-198.5%
*-commutative98.5%
+-commutative98.5%
Simplified98.5%
if -2e4 < (-.f64 1 z) < 2Initial program 100.0%
Taylor expanded in z around 0 98.8%
+-commutative98.8%
Simplified98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (<= (- 1.0 z) 1.0))) (if (or t_0 (not t_0)) (* y (- 1.0 z)) (+ x y))))
double code(double x, double y, double z) {
int t_0 = (1.0 - z) <= 1.0;
double tmp;
if (t_0 || !t_0) {
tmp = y * (1.0 - 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
logical :: t_0
real(8) :: tmp
t_0 = (1.0d0 - z) <= 1.0d0
if (t_0 .or. (.not. t_0)) then
tmp = y * (1.0d0 - z)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
boolean t_0 = (1.0 - z) <= 1.0;
double tmp;
if (t_0 || !t_0) {
tmp = y * (1.0 - z);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - z) <= 1.0 tmp = 0 if t_0 or not t_0: tmp = y * (1.0 - z) else: tmp = x + y return tmp
function code(x, y, z) t_0 = Float64(1.0 - z) <= 1.0 tmp = 0.0 if (t_0 || !t_0) tmp = Float64(y * Float64(1.0 - z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - z) <= 1.0; tmp = 0.0; if (t_0 || ~(t_0)) tmp = y * (1.0 - z); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = LessEqual[N[(1.0 - z), $MachinePrecision], 1.0]}, If[Or[t$95$0, N[Not[t$95$0], $MachinePrecision]], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - z \leq 1\\
\mathbf{if}\;t_0 \lor \neg t_0:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (-.f64 1 z) < 1 or 1 < (-.f64 1 z) Initial program 100.0%
Taylor expanded in x around 0 53.5%
if 1 < (-.f64 1 z) < 1Initial program 100.0%
Taylor expanded in z around 0 49.7%
+-commutative49.7%
Simplified49.7%
Final simplification53.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2600000000.0) (not (<= z 1.0))) (* y (- z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2600000000.0) || !(z <= 1.0)) {
tmp = y * -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 <= (-2600000000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = y * -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 <= -2600000000.0) || !(z <= 1.0)) {
tmp = y * -z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2600000000.0) or not (z <= 1.0): tmp = y * -z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2600000000.0) || !(z <= 1.0)) tmp = Float64(y * Float64(-z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2600000000.0) || ~((z <= 1.0))) tmp = y * -z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2600000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2600000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2.6e9 or 1 < z Initial program 100.0%
sub-neg100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 55.0%
mul-1-neg55.0%
Simplified55.0%
Taylor expanded in z around inf 54.6%
associate-*r*54.6%
neg-mul-154.6%
Simplified54.6%
if -2.6e9 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.1%
+-commutative98.1%
Simplified98.1%
Final simplification75.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.8e-140) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e-140) {
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 <= (-1.8d-140)) 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 <= -1.8e-140) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e-140: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e-140) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e-140) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e-140], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-140}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.8e-140Initial program 100.0%
Taylor expanded in x around inf 67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in z around 0 34.6%
if -1.8e-140 < x Initial program 100.0%
Taylor expanded in x around 0 64.6%
Taylor expanded in z around 0 32.0%
Final simplification33.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 49.7%
+-commutative49.7%
Simplified49.7%
Final simplification49.7%
(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 49.2%
*-commutative49.2%
Simplified49.2%
Taylor expanded in z around 0 24.4%
Final simplification24.4%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))