
(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 (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.05e+168)
(* x z)
(if (<= x -8.5e+64)
(* x y)
(if (<= x -1.36e+47)
(* x z)
(if (<= x -3.9e-76)
(* x y)
(if (<= x 2.1e-19) (- z) (if (<= x 5.5e+227) (* x y) (* x z))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e+168) {
tmp = x * z;
} else if (x <= -8.5e+64) {
tmp = x * y;
} else if (x <= -1.36e+47) {
tmp = x * z;
} else if (x <= -3.9e-76) {
tmp = x * y;
} else if (x <= 2.1e-19) {
tmp = -z;
} else if (x <= 5.5e+227) {
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 (x <= (-1.05d+168)) then
tmp = x * z
else if (x <= (-8.5d+64)) then
tmp = x * y
else if (x <= (-1.36d+47)) then
tmp = x * z
else if (x <= (-3.9d-76)) then
tmp = x * y
else if (x <= 2.1d-19) then
tmp = -z
else if (x <= 5.5d+227) 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 (x <= -1.05e+168) {
tmp = x * z;
} else if (x <= -8.5e+64) {
tmp = x * y;
} else if (x <= -1.36e+47) {
tmp = x * z;
} else if (x <= -3.9e-76) {
tmp = x * y;
} else if (x <= 2.1e-19) {
tmp = -z;
} else if (x <= 5.5e+227) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e+168: tmp = x * z elif x <= -8.5e+64: tmp = x * y elif x <= -1.36e+47: tmp = x * z elif x <= -3.9e-76: tmp = x * y elif x <= 2.1e-19: tmp = -z elif x <= 5.5e+227: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e+168) tmp = Float64(x * z); elseif (x <= -8.5e+64) tmp = Float64(x * y); elseif (x <= -1.36e+47) tmp = Float64(x * z); elseif (x <= -3.9e-76) tmp = Float64(x * y); elseif (x <= 2.1e-19) tmp = Float64(-z); elseif (x <= 5.5e+227) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.05e+168) tmp = x * z; elseif (x <= -8.5e+64) tmp = x * y; elseif (x <= -1.36e+47) tmp = x * z; elseif (x <= -3.9e-76) tmp = x * y; elseif (x <= 2.1e-19) tmp = -z; elseif (x <= 5.5e+227) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e+168], N[(x * z), $MachinePrecision], If[LessEqual[x, -8.5e+64], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.36e+47], N[(x * z), $MachinePrecision], If[LessEqual[x, -3.9e-76], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.1e-19], (-z), If[LessEqual[x, 5.5e+227], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+168}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{+64}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.36 \cdot 10^{+47}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -3.9 \cdot 10^{-76}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-19}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{+227}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.05000000000000001e168 or -8.4999999999999998e64 < x < -1.3599999999999999e47 or 5.5000000000000001e227 < x Initial program 90.7%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 75.2%
if -1.05000000000000001e168 < x < -8.4999999999999998e64 or -1.3599999999999999e47 < x < -3.90000000000000025e-76 or 2.0999999999999999e-19 < x < 5.5000000000000001e227Initial program 100.0%
Taylor expanded in y around inf 63.9%
if -3.90000000000000025e-76 < x < 2.0999999999999999e-19Initial program 100.0%
Taylor expanded in x around 0 82.9%
neg-mul-182.9%
Simplified82.9%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-84) (not (<= x 1.1e-18))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-84) || !(x <= 1.1e-18)) {
tmp = x * (z + y);
} 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 <= (-4.5d-84)) .or. (.not. (x <= 1.1d-18))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-84) || !(x <= 1.1e-18)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-84) or not (x <= 1.1e-18): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-84) || !(x <= 1.1e-18)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e-84) || ~((x <= 1.1e-18))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-84], N[Not[LessEqual[x, 1.1e-18]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-84} \lor \neg \left(x \leq 1.1 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.50000000000000016e-84 or 1.0999999999999999e-18 < x Initial program 97.0%
Taylor expanded in x around inf 93.6%
+-commutative93.6%
Simplified93.6%
if -4.50000000000000016e-84 < x < 1.0999999999999999e-18Initial program 100.0%
Taylor expanded in x around 0 82.9%
neg-mul-182.9%
Simplified82.9%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e-78) (not (<= x 1.35e-18))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e-78) || !(x <= 1.35e-18)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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 <= (-4.1d-78)) .or. (.not. (x <= 1.35d-18))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e-78) || !(x <= 1.35e-18)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.1e-78) or not (x <= 1.35e-18): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e-78) || !(x <= 1.35e-18)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.1e-78) || ~((x <= 1.35e-18))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e-78], N[Not[LessEqual[x, 1.35e-18]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{-78} \lor \neg \left(x \leq 1.35 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -4.0999999999999998e-78 or 1.34999999999999994e-18 < x Initial program 97.0%
Taylor expanded in x around inf 93.6%
+-commutative93.6%
Simplified93.6%
if -4.0999999999999998e-78 < x < 1.34999999999999994e-18Initial program 100.0%
Taylor expanded in y around 0 82.9%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e-76) (* x y) (if (<= x 2.2e-19) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e-76) {
tmp = x * y;
} else if (x <= 2.2e-19) {
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 <= (-4.2d-76)) then
tmp = x * y
else if (x <= 2.2d-19) 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 <= -4.2e-76) {
tmp = x * y;
} else if (x <= 2.2e-19) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.2e-76: tmp = x * y elif x <= 2.2e-19: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.2e-76) tmp = Float64(x * y); elseif (x <= 2.2e-19) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.2e-76) tmp = x * y; elseif (x <= 2.2e-19) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.2e-76], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.2e-19], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-76}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{-19}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.19999999999999985e-76 or 2.1999999999999998e-19 < x Initial program 97.0%
Taylor expanded in y around inf 54.6%
if -4.19999999999999985e-76 < x < 2.1999999999999998e-19Initial program 100.0%
Taylor expanded in x around 0 82.9%
neg-mul-182.9%
Simplified82.9%
Final simplification67.9%
(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.4%
Taylor expanded in x around 0 42.6%
neg-mul-142.6%
Simplified42.6%
Final simplification42.6%
herbie shell --seed 2023264
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))