
(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 7 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 (fma (+ y z) x (- z)))
double code(double x, double y, double z) {
return fma((y + z), x, -z);
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, -z\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
metadata-eval98.0%
distribute-rgt-in98.0%
neg-mul-198.0%
associate-+l+98.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -4.4e+173)
(* z x)
(if (<= x -1.08e+49)
(* y x)
(if (<= x -1.0) (* z x) (if (<= x 8.6e-25) (- z) (* y x))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e+173) {
tmp = z * x;
} else if (x <= -1.08e+49) {
tmp = y * x;
} else if (x <= -1.0) {
tmp = z * x;
} else if (x <= 8.6e-25) {
tmp = -z;
} else {
tmp = y * 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 (x <= (-4.4d+173)) then
tmp = z * x
else if (x <= (-1.08d+49)) then
tmp = y * x
else if (x <= (-1.0d0)) then
tmp = z * x
else if (x <= 8.6d-25) then
tmp = -z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e+173) {
tmp = z * x;
} else if (x <= -1.08e+49) {
tmp = y * x;
} else if (x <= -1.0) {
tmp = z * x;
} else if (x <= 8.6e-25) {
tmp = -z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.4e+173: tmp = z * x elif x <= -1.08e+49: tmp = y * x elif x <= -1.0: tmp = z * x elif x <= 8.6e-25: tmp = -z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.4e+173) tmp = Float64(z * x); elseif (x <= -1.08e+49) tmp = Float64(y * x); elseif (x <= -1.0) tmp = Float64(z * x); elseif (x <= 8.6e-25) tmp = Float64(-z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.4e+173) tmp = z * x; elseif (x <= -1.08e+49) tmp = y * x; elseif (x <= -1.0) tmp = z * x; elseif (x <= 8.6e-25) tmp = -z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.4e+173], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.08e+49], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 8.6e-25], (-z), N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+173}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -1.08 \cdot 10^{+49}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{-25}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.4e173 or -1.08000000000000001e49 < x < -1Initial program 97.5%
Taylor expanded in x around inf 99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in z around inf 76.6%
if -4.4e173 < x < -1.08000000000000001e49 or 8.59999999999999953e-25 < x Initial program 96.2%
Taylor expanded in y around inf 64.3%
if -1 < x < 8.59999999999999953e-25Initial program 100.0%
Taylor expanded in x around 0 74.2%
neg-mul-174.2%
Simplified74.2%
Final simplification70.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-13) (not (<= x 1.15e-24))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-13) || !(x <= 1.15e-24)) {
tmp = (y + z) * x;
} else {
tmp = -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 <= (-9d-13)) .or. (.not. (x <= 1.15d-24))) then
tmp = (y + z) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-13) || !(x <= 1.15e-24)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-13) or not (x <= 1.15e-24): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-13) || !(x <= 1.15e-24)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e-13) || ~((x <= 1.15e-24))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-13], N[Not[LessEqual[x, 1.15e-24]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-13} \lor \neg \left(x \leq 1.15 \cdot 10^{-24}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -9e-13 or 1.1500000000000001e-24 < x Initial program 96.7%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
Simplified97.4%
if -9e-13 < x < 1.1500000000000001e-24Initial program 100.0%
Taylor expanded in x around 0 76.1%
neg-mul-176.1%
Simplified76.1%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.000165) (not (<= x 1.7e-25))) (* (+ y z) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.000165) || !(x <= 1.7e-25)) {
tmp = (y + z) * x;
} else {
tmp = (z * 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 ((x <= (-0.000165d0)) .or. (.not. (x <= 1.7d-25))) then
tmp = (y + z) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.000165) || !(x <= 1.7e-25)) {
tmp = (y + z) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.000165) or not (x <= 1.7e-25): tmp = (y + z) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.000165) || !(x <= 1.7e-25)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.000165) || ~((x <= 1.7e-25))) tmp = (y + z) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.000165], N[Not[LessEqual[x, 1.7e-25]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000165 \lor \neg \left(x \leq 1.7 \cdot 10^{-25}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
if x < -1.65e-4 or 1.70000000000000001e-25 < x Initial program 96.6%
Taylor expanded in x around inf 99.2%
+-commutative99.2%
Simplified99.2%
if -1.65e-4 < x < 1.70000000000000001e-25Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 75.6%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-12) (not (<= x 1.16e-24))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-12) || !(x <= 1.16e-24)) {
tmp = y * x;
} else {
tmp = -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.2d-12)) .or. (.not. (x <= 1.16d-24))) then
tmp = y * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-12) || !(x <= 1.16e-24)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-12) or not (x <= 1.16e-24): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-12) || !(x <= 1.16e-24)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.2e-12) || ~((x <= 1.16e-24))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-12], N[Not[LessEqual[x, 1.16e-24]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-12} \lor \neg \left(x \leq 1.16 \cdot 10^{-24}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.19999999999999994e-12 or 1.16e-24 < x Initial program 96.7%
Taylor expanded in y around inf 55.4%
if -1.19999999999999994e-12 < x < 1.16e-24Initial program 100.0%
Taylor expanded in x around 0 76.1%
neg-mul-176.1%
Simplified76.1%
Final simplification63.8%
(FPCore (x y z) :precision binary64 (- (* (+ y z) x) z))
double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y + z) * x) - z
end function
public static double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
def code(x, y, z): return ((y + z) * x) - z
function code(x, y, z) return Float64(Float64(Float64(y + z) * x) - z) end
function tmp = code(x, y, z) tmp = ((y + z) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + z\right) \cdot x - z
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(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 33.4%
neg-mul-133.4%
Simplified33.4%
Final simplification33.4%
herbie shell --seed 2023334
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))