
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.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)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z): return (x * (y + z)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (y + z)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (+ y z)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.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)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) + (z * 5.0);
}
def code(x, y, z): return (x * (y + z)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (y + z)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) + z \cdot 5
\end{array}
(FPCore (x y z) :precision binary64 (fma z 5.0 (* x (+ z y))))
double code(double x, double y, double z) {
return fma(z, 5.0, (x * (z + y)));
}
function code(x, y, z) return fma(z, 5.0, Float64(x * Float64(z + y))) end
code[x_, y_, z_] := N[(z * 5.0 + N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, 5, x \cdot \left(z + y\right)\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-define100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -0.0078)
t_0
(if (<= x -2.6e-101)
(* z 5.0)
(if (<= x -4.1e-153) (* x y) (if (<= x 3.2e-55) (* z 5.0) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -0.0078) {
tmp = t_0;
} else if (x <= -2.6e-101) {
tmp = z * 5.0;
} else if (x <= -4.1e-153) {
tmp = x * y;
} else if (x <= 3.2e-55) {
tmp = z * 5.0;
} 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 = x * (z + y)
if (x <= (-0.0078d0)) then
tmp = t_0
else if (x <= (-2.6d-101)) then
tmp = z * 5.0d0
else if (x <= (-4.1d-153)) then
tmp = x * y
else if (x <= 3.2d-55) then
tmp = z * 5.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -0.0078) {
tmp = t_0;
} else if (x <= -2.6e-101) {
tmp = z * 5.0;
} else if (x <= -4.1e-153) {
tmp = x * y;
} else if (x <= 3.2e-55) {
tmp = z * 5.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -0.0078: tmp = t_0 elif x <= -2.6e-101: tmp = z * 5.0 elif x <= -4.1e-153: tmp = x * y elif x <= 3.2e-55: tmp = z * 5.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + y)) tmp = 0.0 if (x <= -0.0078) tmp = t_0; elseif (x <= -2.6e-101) tmp = Float64(z * 5.0); elseif (x <= -4.1e-153) tmp = Float64(x * y); elseif (x <= 3.2e-55) tmp = Float64(z * 5.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + y); tmp = 0.0; if (x <= -0.0078) tmp = t_0; elseif (x <= -2.6e-101) tmp = z * 5.0; elseif (x <= -4.1e-153) tmp = x * y; elseif (x <= 3.2e-55) tmp = z * 5.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0078], t$95$0, If[LessEqual[x, -2.6e-101], N[(z * 5.0), $MachinePrecision], If[LessEqual[x, -4.1e-153], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.2e-55], N[(z * 5.0), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -0.0078:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-101}:\\
\;\;\;\;z \cdot 5\\
\mathbf{elif}\;x \leq -4.1 \cdot 10^{-153}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-55}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.0077999999999999996 or 3.2000000000000001e-55 < x Initial program 100.0%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
Simplified97.4%
if -0.0077999999999999996 < x < -2.6000000000000001e-101 or -4.1e-153 < x < 3.2000000000000001e-55Initial program 99.8%
Taylor expanded in x around 0 85.9%
if -2.6000000000000001e-101 < x < -4.1e-153Initial program 99.9%
Taylor expanded in y around inf 70.1%
Final simplification91.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -6e+24)
t_0
(if (<= x -4.2e-101)
(* z (+ 5.0 x))
(if (<= x -4.1e-153) (* x y) (if (<= x 2.7e-56) (* z 5.0) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -6e+24) {
tmp = t_0;
} else if (x <= -4.2e-101) {
tmp = z * (5.0 + x);
} else if (x <= -4.1e-153) {
tmp = x * y;
} else if (x <= 2.7e-56) {
tmp = z * 5.0;
} 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 = x * (z + y)
if (x <= (-6d+24)) then
tmp = t_0
else if (x <= (-4.2d-101)) then
tmp = z * (5.0d0 + x)
else if (x <= (-4.1d-153)) then
tmp = x * y
else if (x <= 2.7d-56) then
tmp = z * 5.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -6e+24) {
tmp = t_0;
} else if (x <= -4.2e-101) {
tmp = z * (5.0 + x);
} else if (x <= -4.1e-153) {
tmp = x * y;
} else if (x <= 2.7e-56) {
tmp = z * 5.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -6e+24: tmp = t_0 elif x <= -4.2e-101: tmp = z * (5.0 + x) elif x <= -4.1e-153: tmp = x * y elif x <= 2.7e-56: tmp = z * 5.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + y)) tmp = 0.0 if (x <= -6e+24) tmp = t_0; elseif (x <= -4.2e-101) tmp = Float64(z * Float64(5.0 + x)); elseif (x <= -4.1e-153) tmp = Float64(x * y); elseif (x <= 2.7e-56) tmp = Float64(z * 5.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + y); tmp = 0.0; if (x <= -6e+24) tmp = t_0; elseif (x <= -4.2e-101) tmp = z * (5.0 + x); elseif (x <= -4.1e-153) tmp = x * y; elseif (x <= 2.7e-56) tmp = z * 5.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6e+24], t$95$0, If[LessEqual[x, -4.2e-101], N[(z * N[(5.0 + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -4.1e-153], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.7e-56], N[(z * 5.0), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -6 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -4.2 \cdot 10^{-101}:\\
\;\;\;\;z \cdot \left(5 + x\right)\\
\mathbf{elif}\;x \leq -4.1 \cdot 10^{-153}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-56}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.9999999999999999e24 or 2.69999999999999995e-56 < x Initial program 100.0%
Taylor expanded in x around inf 97.3%
+-commutative97.3%
Simplified97.3%
if -5.9999999999999999e24 < x < -4.20000000000000031e-101Initial program 99.8%
Taylor expanded in y around 0 83.4%
distribute-rgt-in83.4%
Simplified83.4%
if -4.20000000000000031e-101 < x < -4.1e-153Initial program 99.9%
Taylor expanded in y around inf 70.1%
if -4.1e-153 < x < 2.69999999999999995e-56Initial program 99.8%
Taylor expanded in x around 0 89.1%
Final simplification91.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -0.00155)
(not
(or (<= x -6.5e-101) (and (not (<= x -4.1e-153)) (<= x 3.5e-54)))))
(* x y)
(* z 5.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.00155) || !((x <= -6.5e-101) || (!(x <= -4.1e-153) && (x <= 3.5e-54)))) {
tmp = x * y;
} else {
tmp = z * 5.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) :: tmp
if ((x <= (-0.00155d0)) .or. (.not. (x <= (-6.5d-101)) .or. (.not. (x <= (-4.1d-153))) .and. (x <= 3.5d-54))) then
tmp = x * y
else
tmp = z * 5.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.00155) || !((x <= -6.5e-101) || (!(x <= -4.1e-153) && (x <= 3.5e-54)))) {
tmp = x * y;
} else {
tmp = z * 5.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.00155) or not ((x <= -6.5e-101) or (not (x <= -4.1e-153) and (x <= 3.5e-54))): tmp = x * y else: tmp = z * 5.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.00155) || !((x <= -6.5e-101) || (!(x <= -4.1e-153) && (x <= 3.5e-54)))) tmp = Float64(x * y); else tmp = Float64(z * 5.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.00155) || ~(((x <= -6.5e-101) || (~((x <= -4.1e-153)) && (x <= 3.5e-54))))) tmp = x * y; else tmp = z * 5.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.00155], N[Not[Or[LessEqual[x, -6.5e-101], And[N[Not[LessEqual[x, -4.1e-153]], $MachinePrecision], LessEqual[x, 3.5e-54]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(z * 5.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00155 \lor \neg \left(x \leq -6.5 \cdot 10^{-101} \lor \neg \left(x \leq -4.1 \cdot 10^{-153}\right) \land x \leq 3.5 \cdot 10^{-54}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5\\
\end{array}
\end{array}
if x < -0.00154999999999999995 or -6.4999999999999996e-101 < x < -4.1e-153 or 3.49999999999999982e-54 < x Initial program 100.0%
Taylor expanded in y around inf 51.8%
if -0.00154999999999999995 < x < -6.4999999999999996e-101 or -4.1e-153 < x < 3.49999999999999982e-54Initial program 99.8%
Taylor expanded in x around 0 85.9%
Final simplification65.3%
(FPCore (x y z)
:precision binary64
(if (<= x -5.0)
(* z x)
(if (or (<= x -2.6e-101) (and (not (<= x -4.1e-153)) (<= x 4e-54)))
(* z 5.0)
(* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.0) {
tmp = z * x;
} else if ((x <= -2.6e-101) || (!(x <= -4.1e-153) && (x <= 4e-54))) {
tmp = z * 5.0;
} 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 (x <= (-5.0d0)) then
tmp = z * x
else if ((x <= (-2.6d-101)) .or. (.not. (x <= (-4.1d-153))) .and. (x <= 4d-54)) then
tmp = z * 5.0d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.0) {
tmp = z * x;
} else if ((x <= -2.6e-101) || (!(x <= -4.1e-153) && (x <= 4e-54))) {
tmp = z * 5.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.0: tmp = z * x elif (x <= -2.6e-101) or (not (x <= -4.1e-153) and (x <= 4e-54)): tmp = z * 5.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.0) tmp = Float64(z * x); elseif ((x <= -2.6e-101) || (!(x <= -4.1e-153) && (x <= 4e-54))) tmp = Float64(z * 5.0); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.0) tmp = z * x; elseif ((x <= -2.6e-101) || (~((x <= -4.1e-153)) && (x <= 4e-54))) tmp = z * 5.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.0], N[(z * x), $MachinePrecision], If[Or[LessEqual[x, -2.6e-101], And[N[Not[LessEqual[x, -4.1e-153]], $MachinePrecision], LessEqual[x, 4e-54]]], N[(z * 5.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-101} \lor \neg \left(x \leq -4.1 \cdot 10^{-153}\right) \land x \leq 4 \cdot 10^{-54}:\\
\;\;\;\;z \cdot 5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 63.5%
if -5 < x < -2.6000000000000001e-101 or -4.1e-153 < x < 4.0000000000000001e-54Initial program 99.8%
Taylor expanded in x around 0 85.9%
if -2.6000000000000001e-101 < x < -4.1e-153 or 4.0000000000000001e-54 < x Initial program 100.0%
Taylor expanded in y around inf 57.1%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.0) (not (<= x 5e-9))) (* x (+ z y)) (+ (* z 5.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 5e-9)) {
tmp = x * (z + y);
} else {
tmp = (z * 5.0) + (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 ((x <= (-5.0d0)) .or. (.not. (x <= 5d-9))) then
tmp = x * (z + y)
else
tmp = (z * 5.0d0) + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.0) || !(x <= 5e-9)) {
tmp = x * (z + y);
} else {
tmp = (z * 5.0) + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.0) or not (x <= 5e-9): tmp = x * (z + y) else: tmp = (z * 5.0) + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.0) || !(x <= 5e-9)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(z * 5.0) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.0) || ~((x <= 5e-9))) tmp = x * (z + y); else tmp = (z * 5.0) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.0], N[Not[LessEqual[x, 5e-9]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(z * 5.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \lor \neg \left(x \leq 5 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot 5 + x \cdot y\\
\end{array}
\end{array}
if x < -5 or 5.0000000000000001e-9 < x Initial program 100.0%
Taylor expanded in x around inf 99.3%
+-commutative99.3%
Simplified99.3%
if -5 < x < 5.0000000000000001e-9Initial program 99.8%
+-commutative99.8%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 84.3%
associate-/l*84.0%
distribute-rgt-out84.6%
+-commutative84.6%
Simplified84.6%
Taylor expanded in x around 0 83.3%
Taylor expanded in y around 0 97.9%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (+ (* x (+ z y)) (* z 5.0)))
double code(double x, double y, double z) {
return (x * (z + y)) + (z * 5.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 * (z + y)) + (z * 5.0d0)
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) + (z * 5.0);
}
def code(x, y, z): return (x * (z + y)) + (z * 5.0)
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) + Float64(z * 5.0)) end
function tmp = code(x, y, z) tmp = (x * (z + y)) + (z * 5.0); end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] + N[(z * 5.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) + z \cdot 5
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (* z 5.0))
double code(double x, double y, double z) {
return z * 5.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * 5.0d0
end function
public static double code(double x, double y, double z) {
return z * 5.0;
}
def code(x, y, z): return z * 5.0
function code(x, y, z) return Float64(z * 5.0) end
function tmp = code(x, y, z) tmp = z * 5.0; end
code[x_, y_, z_] := N[(z * 5.0), $MachinePrecision]
\begin{array}{l}
\\
z \cdot 5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 38.5%
Final simplification38.5%
(FPCore (x y z) :precision binary64 (+ (* (+ x 5.0) z) (* x y)))
double code(double x, double y, double z) {
return ((x + 5.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 = ((x + 5.0d0) * z) + (x * y)
end function
public static double code(double x, double y, double z) {
return ((x + 5.0) * z) + (x * y);
}
def code(x, y, z): return ((x + 5.0) * z) + (x * y)
function code(x, y, z) return Float64(Float64(Float64(x + 5.0) * z) + Float64(x * y)) end
function tmp = code(x, y, z) tmp = ((x + 5.0) * z) + (x * y); end
code[x_, y_, z_] := N[(N[(N[(x + 5.0), $MachinePrecision] * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 5\right) \cdot z + x \cdot y
\end{array}
herbie shell --seed 2024079
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
:precision binary64
:alt
(+ (* (+ x 5.0) z) (* x y))
(+ (* x (+ y z)) (* z 5.0)))