
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
associate-+r+98.0%
metadata-eval98.0%
mul-1-neg98.0%
unsub-neg98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -9e+57)
(* x z)
(if (<= x -7.6e-25)
(* x y)
(if (<= x 5.8e-68)
(- z)
(if (<= x 1.8e-36)
(* x y)
(if (<= x 6e-12)
(- z)
(if (<= x 2.2e+73)
(* x y)
(if (or (<= x 1.8e+182)
(and (not (<= x 1.85e+207)) (<= x 1.5e+301)))
(* x z)
(* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9e+57) {
tmp = x * z;
} else if (x <= -7.6e-25) {
tmp = x * y;
} else if (x <= 5.8e-68) {
tmp = -z;
} else if (x <= 1.8e-36) {
tmp = x * y;
} else if (x <= 6e-12) {
tmp = -z;
} else if (x <= 2.2e+73) {
tmp = x * y;
} else if ((x <= 1.8e+182) || (!(x <= 1.85e+207) && (x <= 1.5e+301))) {
tmp = 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 (x <= (-9d+57)) then
tmp = x * z
else if (x <= (-7.6d-25)) then
tmp = x * y
else if (x <= 5.8d-68) then
tmp = -z
else if (x <= 1.8d-36) then
tmp = x * y
else if (x <= 6d-12) then
tmp = -z
else if (x <= 2.2d+73) then
tmp = x * y
else if ((x <= 1.8d+182) .or. (.not. (x <= 1.85d+207)) .and. (x <= 1.5d+301)) then
tmp = 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 (x <= -9e+57) {
tmp = x * z;
} else if (x <= -7.6e-25) {
tmp = x * y;
} else if (x <= 5.8e-68) {
tmp = -z;
} else if (x <= 1.8e-36) {
tmp = x * y;
} else if (x <= 6e-12) {
tmp = -z;
} else if (x <= 2.2e+73) {
tmp = x * y;
} else if ((x <= 1.8e+182) || (!(x <= 1.85e+207) && (x <= 1.5e+301))) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9e+57: tmp = x * z elif x <= -7.6e-25: tmp = x * y elif x <= 5.8e-68: tmp = -z elif x <= 1.8e-36: tmp = x * y elif x <= 6e-12: tmp = -z elif x <= 2.2e+73: tmp = x * y elif (x <= 1.8e+182) or (not (x <= 1.85e+207) and (x <= 1.5e+301)): tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9e+57) tmp = Float64(x * z); elseif (x <= -7.6e-25) tmp = Float64(x * y); elseif (x <= 5.8e-68) tmp = Float64(-z); elseif (x <= 1.8e-36) tmp = Float64(x * y); elseif (x <= 6e-12) tmp = Float64(-z); elseif (x <= 2.2e+73) tmp = Float64(x * y); elseif ((x <= 1.8e+182) || (!(x <= 1.85e+207) && (x <= 1.5e+301))) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9e+57) tmp = x * z; elseif (x <= -7.6e-25) tmp = x * y; elseif (x <= 5.8e-68) tmp = -z; elseif (x <= 1.8e-36) tmp = x * y; elseif (x <= 6e-12) tmp = -z; elseif (x <= 2.2e+73) tmp = x * y; elseif ((x <= 1.8e+182) || (~((x <= 1.85e+207)) && (x <= 1.5e+301))) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9e+57], N[(x * z), $MachinePrecision], If[LessEqual[x, -7.6e-25], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.8e-68], (-z), If[LessEqual[x, 1.8e-36], N[(x * y), $MachinePrecision], If[LessEqual[x, 6e-12], (-z), If[LessEqual[x, 2.2e+73], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 1.8e+182], And[N[Not[LessEqual[x, 1.85e+207]], $MachinePrecision], LessEqual[x, 1.5e+301]]], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+57}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7.6 \cdot 10^{-25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{-68}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-12}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+73}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+182} \lor \neg \left(x \leq 1.85 \cdot 10^{+207}\right) \land x \leq 1.5 \cdot 10^{+301}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -8.99999999999999991e57 or 2.2e73 < x < 1.8e182 or 1.85e207 < x < 1.5e301Initial program 95.1%
Taylor expanded in y around 0 69.6%
*-commutative69.6%
distribute-lft-out--69.6%
*-rgt-identity69.6%
Simplified69.6%
Taylor expanded in x around inf 69.6%
if -8.99999999999999991e57 < x < -7.5999999999999996e-25 or 5.8000000000000001e-68 < x < 1.80000000000000016e-36 or 6.0000000000000003e-12 < x < 2.2e73 or 1.8e182 < x < 1.85e207 or 1.5e301 < x Initial program 98.1%
Taylor expanded in y around inf 76.2%
if -7.5999999999999996e-25 < x < 5.8000000000000001e-68 or 1.80000000000000016e-36 < x < 6.0000000000000003e-12Initial program 100.0%
Taylor expanded in x around 0 78.0%
mul-1-neg78.0%
Simplified78.0%
Final simplification74.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ y z))))
(if (<= x -3.4e-25)
t_0
(if (<= x 6.2e-61)
(- z)
(if (<= x 3.8e-36) (* x y) (if (<= x 3.25e-12) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -3.4e-25) {
tmp = t_0;
} else if (x <= 6.2e-61) {
tmp = -z;
} else if (x <= 3.8e-36) {
tmp = x * y;
} else if (x <= 3.25e-12) {
tmp = -z;
} 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 * (y + z)
if (x <= (-3.4d-25)) then
tmp = t_0
else if (x <= 6.2d-61) then
tmp = -z
else if (x <= 3.8d-36) then
tmp = x * y
else if (x <= 3.25d-12) then
tmp = -z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -3.4e-25) {
tmp = t_0;
} else if (x <= 6.2e-61) {
tmp = -z;
} else if (x <= 3.8e-36) {
tmp = x * y;
} else if (x <= 3.25e-12) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -3.4e-25: tmp = t_0 elif x <= 6.2e-61: tmp = -z elif x <= 3.8e-36: tmp = x * y elif x <= 3.25e-12: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -3.4e-25) tmp = t_0; elseif (x <= 6.2e-61) tmp = Float64(-z); elseif (x <= 3.8e-36) tmp = Float64(x * y); elseif (x <= 3.25e-12) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + z); tmp = 0.0; if (x <= -3.4e-25) tmp = t_0; elseif (x <= 6.2e-61) tmp = -z; elseif (x <= 3.8e-36) tmp = x * y; elseif (x <= 3.25e-12) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.4e-25], t$95$0, If[LessEqual[x, 6.2e-61], (-z), If[LessEqual[x, 3.8e-36], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.25e-12], (-z), t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -3.4 \cdot 10^{-25}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-61}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.25 \cdot 10^{-12}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -3.40000000000000002e-25 or 3.2500000000000001e-12 < x Initial program 96.1%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -3.40000000000000002e-25 < x < 6.1999999999999999e-61 or 3.79999999999999971e-36 < x < 3.2500000000000001e-12Initial program 100.0%
Taylor expanded in x around 0 78.0%
mul-1-neg78.0%
Simplified78.0%
if 6.1999999999999999e-61 < x < 3.79999999999999971e-36Initial program 100.0%
Taylor expanded in y around inf 83.7%
Final simplification88.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ y z))))
(if (<= x -1.25e-24)
t_0
(if (<= x 3.4e-61)
(- (* x z) z)
(if (<= x 1.8e-36) (* x y) (if (<= x 1.45e-10) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -1.25e-24) {
tmp = t_0;
} else if (x <= 3.4e-61) {
tmp = (x * z) - z;
} else if (x <= 1.8e-36) {
tmp = x * y;
} else if (x <= 1.45e-10) {
tmp = -z;
} 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 * (y + z)
if (x <= (-1.25d-24)) then
tmp = t_0
else if (x <= 3.4d-61) then
tmp = (x * z) - z
else if (x <= 1.8d-36) then
tmp = x * y
else if (x <= 1.45d-10) then
tmp = -z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + z);
double tmp;
if (x <= -1.25e-24) {
tmp = t_0;
} else if (x <= 3.4e-61) {
tmp = (x * z) - z;
} else if (x <= 1.8e-36) {
tmp = x * y;
} else if (x <= 1.45e-10) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + z) tmp = 0 if x <= -1.25e-24: tmp = t_0 elif x <= 3.4e-61: tmp = (x * z) - z elif x <= 1.8e-36: tmp = x * y elif x <= 1.45e-10: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + z)) tmp = 0.0 if (x <= -1.25e-24) tmp = t_0; elseif (x <= 3.4e-61) tmp = Float64(Float64(x * z) - z); elseif (x <= 1.8e-36) tmp = Float64(x * y); elseif (x <= 1.45e-10) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + z); tmp = 0.0; if (x <= -1.25e-24) tmp = t_0; elseif (x <= 3.4e-61) tmp = (x * z) - z; elseif (x <= 1.8e-36) tmp = x * y; elseif (x <= 1.45e-10) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.25e-24], t$95$0, If[LessEqual[x, 3.4e-61], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], If[LessEqual[x, 1.8e-36], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.45e-10], (-z), t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq -1.25 \cdot 10^{-24}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{-61}:\\
\;\;\;\;x \cdot z - z\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-10}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.24999999999999995e-24 or 1.4499999999999999e-10 < x Initial program 96.1%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -1.24999999999999995e-24 < x < 3.3999999999999998e-61Initial program 100.0%
Taylor expanded in y around 0 77.0%
*-commutative77.0%
distribute-lft-out--77.0%
*-rgt-identity77.0%
Simplified77.0%
if 3.3999999999999998e-61 < x < 1.80000000000000016e-36Initial program 100.0%
Taylor expanded in y around inf 83.7%
if 1.80000000000000016e-36 < x < 1.4499999999999999e-10Initial program 100.0%
Taylor expanded in x around 0 100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification88.7%
(FPCore (x y z)
:precision binary64
(if (<= x -1.3e-24)
(* x y)
(if (or (<= x 6.5e-61) (and (not (<= x 4.4e-36)) (<= x 1.32e-14)))
(- z)
(* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e-24) {
tmp = x * y;
} else if ((x <= 6.5e-61) || (!(x <= 4.4e-36) && (x <= 1.32e-14))) {
tmp = -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 (x <= (-1.3d-24)) then
tmp = x * y
else if ((x <= 6.5d-61) .or. (.not. (x <= 4.4d-36)) .and. (x <= 1.32d-14)) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e-24) {
tmp = x * y;
} else if ((x <= 6.5e-61) || (!(x <= 4.4e-36) && (x <= 1.32e-14))) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.3e-24: tmp = x * y elif (x <= 6.5e-61) or (not (x <= 4.4e-36) and (x <= 1.32e-14)): tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.3e-24) tmp = Float64(x * y); elseif ((x <= 6.5e-61) || (!(x <= 4.4e-36) && (x <= 1.32e-14))) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.3e-24) tmp = x * y; elseif ((x <= 6.5e-61) || (~((x <= 4.4e-36)) && (x <= 1.32e-14))) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.3e-24], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 6.5e-61], And[N[Not[LessEqual[x, 4.4e-36]], $MachinePrecision], LessEqual[x, 1.32e-14]]], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-24}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-61} \lor \neg \left(x \leq 4.4 \cdot 10^{-36}\right) \land x \leq 1.32 \cdot 10^{-14}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.3e-24 or 6.4999999999999994e-61 < x < 4.3999999999999999e-36 or 1.32e-14 < x Initial program 96.3%
Taylor expanded in y around inf 51.1%
if -1.3e-24 < x < 6.4999999999999994e-61 or 4.3999999999999999e-36 < x < 1.32e-14Initial program 100.0%
Taylor expanded in x around 0 78.0%
mul-1-neg78.0%
Simplified78.0%
Final simplification63.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 38.8%
mul-1-neg38.8%
Simplified38.8%
Final simplification38.8%
herbie shell --seed 2023199
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))