
(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 (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.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
*-commutative100.0%
fma-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -6.6e-87)
(* y x)
(if (<= x 6e-179)
(- z)
(if (<= x 7e-124)
(* y x)
(if (<= x 8.2e-49)
(- z)
(if (or (<= x 3.5e+30) (not (<= x 1.12e+220))) (* y x) (* z x)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.6e-87) {
tmp = y * x;
} else if (x <= 6e-179) {
tmp = -z;
} else if (x <= 7e-124) {
tmp = y * x;
} else if (x <= 8.2e-49) {
tmp = -z;
} else if ((x <= 3.5e+30) || !(x <= 1.12e+220)) {
tmp = y * x;
} else {
tmp = z * 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 <= (-6.6d-87)) then
tmp = y * x
else if (x <= 6d-179) then
tmp = -z
else if (x <= 7d-124) then
tmp = y * x
else if (x <= 8.2d-49) then
tmp = -z
else if ((x <= 3.5d+30) .or. (.not. (x <= 1.12d+220))) then
tmp = y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.6e-87) {
tmp = y * x;
} else if (x <= 6e-179) {
tmp = -z;
} else if (x <= 7e-124) {
tmp = y * x;
} else if (x <= 8.2e-49) {
tmp = -z;
} else if ((x <= 3.5e+30) || !(x <= 1.12e+220)) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.6e-87: tmp = y * x elif x <= 6e-179: tmp = -z elif x <= 7e-124: tmp = y * x elif x <= 8.2e-49: tmp = -z elif (x <= 3.5e+30) or not (x <= 1.12e+220): tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.6e-87) tmp = Float64(y * x); elseif (x <= 6e-179) tmp = Float64(-z); elseif (x <= 7e-124) tmp = Float64(y * x); elseif (x <= 8.2e-49) tmp = Float64(-z); elseif ((x <= 3.5e+30) || !(x <= 1.12e+220)) tmp = Float64(y * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.6e-87) tmp = y * x; elseif (x <= 6e-179) tmp = -z; elseif (x <= 7e-124) tmp = y * x; elseif (x <= 8.2e-49) tmp = -z; elseif ((x <= 3.5e+30) || ~((x <= 1.12e+220))) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.6e-87], N[(y * x), $MachinePrecision], If[LessEqual[x, 6e-179], (-z), If[LessEqual[x, 7e-124], N[(y * x), $MachinePrecision], If[LessEqual[x, 8.2e-49], (-z), If[Or[LessEqual[x, 3.5e+30], N[Not[LessEqual[x, 1.12e+220]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{-87}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-179}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-124}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{-49}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+30} \lor \neg \left(x \leq 1.12 \cdot 10^{+220}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -6.6000000000000001e-87 or 6.00000000000000012e-179 < x < 6.9999999999999997e-124 or 8.2000000000000003e-49 < x < 3.50000000000000021e30 or 1.12000000000000006e220 < x Initial program 98.4%
Taylor expanded in y around inf 62.2%
if -6.6000000000000001e-87 < x < 6.00000000000000012e-179 or 6.9999999999999997e-124 < x < 8.2000000000000003e-49Initial program 100.0%
Taylor expanded in x around 0 79.0%
neg-mul-179.0%
Simplified79.0%
if 3.50000000000000021e30 < x < 1.12000000000000006e220Initial program 97.3%
*-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.3%
metadata-eval97.3%
neg-mul-197.3%
associate-+r+97.3%
unsub-neg97.3%
+-commutative97.3%
distribute-lft-out99.9%
Simplified99.9%
Taylor expanded in y around 0 62.0%
Taylor expanded in x around inf 62.0%
Final simplification67.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (+ y z) x)))
(if (<= x -1.6e-89)
t_0
(if (<= x 6e-179)
(- z)
(if (<= x 7e-124) (* y x) (if (<= x 2.3e-50) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = (y + z) * x;
double tmp;
if (x <= -1.6e-89) {
tmp = t_0;
} else if (x <= 6e-179) {
tmp = -z;
} else if (x <= 7e-124) {
tmp = y * x;
} else if (x <= 2.3e-50) {
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 = (y + z) * x
if (x <= (-1.6d-89)) then
tmp = t_0
else if (x <= 6d-179) then
tmp = -z
else if (x <= 7d-124) then
tmp = y * x
else if (x <= 2.3d-50) 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 = (y + z) * x;
double tmp;
if (x <= -1.6e-89) {
tmp = t_0;
} else if (x <= 6e-179) {
tmp = -z;
} else if (x <= 7e-124) {
tmp = y * x;
} else if (x <= 2.3e-50) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y + z) * x tmp = 0 if x <= -1.6e-89: tmp = t_0 elif x <= 6e-179: tmp = -z elif x <= 7e-124: tmp = y * x elif x <= 2.3e-50: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y + z) * x) tmp = 0.0 if (x <= -1.6e-89) tmp = t_0; elseif (x <= 6e-179) tmp = Float64(-z); elseif (x <= 7e-124) tmp = Float64(y * x); elseif (x <= 2.3e-50) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y + z) * x; tmp = 0.0; if (x <= -1.6e-89) tmp = t_0; elseif (x <= 6e-179) tmp = -z; elseif (x <= 7e-124) tmp = y * x; elseif (x <= 2.3e-50) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.6e-89], t$95$0, If[LessEqual[x, 6e-179], (-z), If[LessEqual[x, 7e-124], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.3e-50], (-z), t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + z\right) \cdot x\\
\mathbf{if}\;x \leq -1.6 \cdot 10^{-89}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-179}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-124}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-50}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.59999999999999999e-89 or 2.3000000000000002e-50 < x Initial program 98.1%
Taylor expanded in x around inf 92.1%
+-commutative92.1%
Simplified92.1%
if -1.59999999999999999e-89 < x < 6.00000000000000012e-179 or 6.9999999999999997e-124 < x < 2.3000000000000002e-50Initial program 100.0%
Taylor expanded in x around 0 79.6%
neg-mul-179.6%
Simplified79.6%
if 6.00000000000000012e-179 < x < 6.9999999999999997e-124Initial program 100.0%
Taylor expanded in y around inf 72.6%
Final simplification87.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -5.7e-86)
(not (or (<= x 6e-179) (and (not (<= x 7e-124)) (<= x 7.5e-48)))))
(* y x)
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.7e-86) || !((x <= 6e-179) || (!(x <= 7e-124) && (x <= 7.5e-48)))) {
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 <= (-5.7d-86)) .or. (.not. (x <= 6d-179) .or. (.not. (x <= 7d-124)) .and. (x <= 7.5d-48))) 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 <= -5.7e-86) || !((x <= 6e-179) || (!(x <= 7e-124) && (x <= 7.5e-48)))) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.7e-86) or not ((x <= 6e-179) or (not (x <= 7e-124) and (x <= 7.5e-48))): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.7e-86) || !((x <= 6e-179) || (!(x <= 7e-124) && (x <= 7.5e-48)))) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.7e-86) || ~(((x <= 6e-179) || (~((x <= 7e-124)) && (x <= 7.5e-48))))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.7e-86], N[Not[Or[LessEqual[x, 6e-179], And[N[Not[LessEqual[x, 7e-124]], $MachinePrecision], LessEqual[x, 7.5e-48]]]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.7 \cdot 10^{-86} \lor \neg \left(x \leq 6 \cdot 10^{-179} \lor \neg \left(x \leq 7 \cdot 10^{-124}\right) \land x \leq 7.5 \cdot 10^{-48}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.7000000000000004e-86 or 6.00000000000000012e-179 < x < 6.9999999999999997e-124 or 7.50000000000000042e-48 < x Initial program 98.2%
Taylor expanded in y around inf 58.3%
if -5.7000000000000004e-86 < x < 6.00000000000000012e-179 or 6.9999999999999997e-124 < x < 7.50000000000000042e-48Initial program 100.0%
Taylor expanded in x around 0 79.0%
neg-mul-179.0%
Simplified79.0%
Final simplification65.4%
(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.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
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.8%
Taylor expanded in x around 0 33.2%
neg-mul-133.2%
Simplified33.2%
Final simplification33.2%
herbie shell --seed 2024039
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))