
(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 8 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 (+ z y) x (- 0.0 z)))
double code(double x, double y, double z) {
return fma((z + y), x, (0.0 - z));
}
function code(x, y, z) return fma(Float64(z + y), x, Float64(0.0 - z)) end
code[x_, y_, z_] := N[(N[(z + y), $MachinePrecision] * x + N[(0.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + y, x, 0 - z\right)
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
sub-negN/A
+-rgt-identityN/A
*-commutativeN/A
sub0-negN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
--lowering--.f64100.0
Applied egg-rr100.0%
neg-sub0N/A
neg-lowering-neg.f64100.0
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.22e+33)
(* z x)
(if (<= x -1.22e-85)
(fma x y 0.0)
(if (<= x 4.7e-30) (- 0.0 z) (fma x y 0.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.22e+33) {
tmp = z * x;
} else if (x <= -1.22e-85) {
tmp = fma(x, y, 0.0);
} else if (x <= 4.7e-30) {
tmp = 0.0 - z;
} else {
tmp = fma(x, y, 0.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.22e+33) tmp = Float64(z * x); elseif (x <= -1.22e-85) tmp = fma(x, y, 0.0); elseif (x <= 4.7e-30) tmp = Float64(0.0 - z); else tmp = fma(x, y, 0.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.22e+33], N[(z * x), $MachinePrecision], If[LessEqual[x, -1.22e-85], N[(x * y + 0.0), $MachinePrecision], If[LessEqual[x, 4.7e-30], N[(0.0 - z), $MachinePrecision], N[(x * y + 0.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{+33}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -1.22 \cdot 10^{-85}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0\right)\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{-30}:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0\right)\\
\end{array}
\end{array}
if x < -1.22000000000000005e33Initial program 96.3%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Simplified100.0%
Taylor expanded in z around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6465.3
Simplified65.3%
+-rgt-identityN/A
*-lowering-*.f6465.3
Applied egg-rr65.3%
if -1.22000000000000005e33 < x < -1.22000000000000006e-85 or 4.69999999999999969e-30 < x Initial program 96.2%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6460.4
Simplified60.4%
if -1.22000000000000006e-85 < x < 4.69999999999999969e-30Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6477.1
Simplified77.1%
sub0-negN/A
neg-lowering-neg.f6477.1
Applied egg-rr77.1%
Final simplification67.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z y) x))) (if (<= x -1.0) t_0 (if (<= x 1.0) (fma y x (- 0.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + y) * x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = fma(y, x, (0.0 - z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z + y) * x) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = fma(y, x, Float64(0.0 - z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(y * x + N[(0.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + y\right) \cdot x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{fma}\left(y, x, 0 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 95.4%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6499.0
Simplified99.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f6499.0
Applied egg-rr99.0%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
sub-negN/A
+-rgt-identityN/A
*-commutativeN/A
sub0-negN/A
accelerator-lowering-fma.f64N/A
+-lowering-+.f64N/A
--lowering--.f64100.0
Applied egg-rr100.0%
neg-sub0N/A
neg-lowering-neg.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around 0
Simplified98.8%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z y) x))) (if (<= x -7.5e-103) t_0 (if (<= x 310.0) (* z (+ x -1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + y) * x;
double tmp;
if (x <= -7.5e-103) {
tmp = t_0;
} else if (x <= 310.0) {
tmp = z * (x + -1.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 = (z + y) * x
if (x <= (-7.5d-103)) then
tmp = t_0
else if (x <= 310.0d0) then
tmp = z * (x + (-1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z + y) * x;
double tmp;
if (x <= -7.5e-103) {
tmp = t_0;
} else if (x <= 310.0) {
tmp = z * (x + -1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z + y) * x tmp = 0 if x <= -7.5e-103: tmp = t_0 elif x <= 310.0: tmp = z * (x + -1.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z + y) * x) tmp = 0.0 if (x <= -7.5e-103) tmp = t_0; elseif (x <= 310.0) tmp = Float64(z * Float64(x + -1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z + y) * x; tmp = 0.0; if (x <= -7.5e-103) tmp = t_0; elseif (x <= 310.0) tmp = z * (x + -1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -7.5e-103], t$95$0, If[LessEqual[x, 310.0], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + y\right) \cdot x\\
\mathbf{if}\;x \leq -7.5 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 310:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.5e-103 or 310 < x Initial program 96.2%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6493.0
Simplified93.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f6493.0
Applied egg-rr93.0%
if -7.5e-103 < x < 310Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
Taylor expanded in z around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6476.6
Simplified76.6%
sub-negN/A
+-rgt-identityN/A
*-commutativeN/A
neg-mul-1N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6476.7
Applied egg-rr76.7%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (<= y -2.95e+153) (fma x y 0.0) (if (<= y 1.16e+29) (* z (+ x -1.0)) (fma x y 0.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.95e+153) {
tmp = fma(x, y, 0.0);
} else if (y <= 1.16e+29) {
tmp = z * (x + -1.0);
} else {
tmp = fma(x, y, 0.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2.95e+153) tmp = fma(x, y, 0.0); elseif (y <= 1.16e+29) tmp = Float64(z * Float64(x + -1.0)); else tmp = fma(x, y, 0.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2.95e+153], N[(x * y + 0.0), $MachinePrecision], If[LessEqual[y, 1.16e+29], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(x * y + 0.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.95 \cdot 10^{+153}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0\right)\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{+29}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 0\right)\\
\end{array}
\end{array}
if y < -2.9500000000000001e153 or 1.16e29 < y Initial program 97.7%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6478.8
Simplified78.8%
if -2.9500000000000001e153 < y < 1.16e29Initial program 97.6%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
Taylor expanded in z around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6478.1
Simplified78.1%
sub-negN/A
+-rgt-identityN/A
*-commutativeN/A
neg-mul-1N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6478.1
Applied egg-rr78.1%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.0) (* z x) (if (<= x 1.0) (- 0.0 z) (* z x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = z * x;
} else if (x <= 1.0) {
tmp = 0.0 - z;
} 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 <= (-1.0d0)) then
tmp = z * x
else if (x <= 1.0d0) then
tmp = 0.0d0 - z
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.0) {
tmp = z * x;
} else if (x <= 1.0) {
tmp = 0.0 - z;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.0: tmp = z * x elif x <= 1.0: tmp = 0.0 - z else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.0) tmp = Float64(z * x); elseif (x <= 1.0) tmp = Float64(0.0 - z); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.0) tmp = z * x; elseif (x <= 1.0) tmp = 0.0 - z; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 1.0], N[(0.0 - z), $MachinePrecision], N[(z * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;0 - z\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 95.4%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f6499.0
Simplified99.0%
Taylor expanded in z around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6450.2
Simplified50.2%
+-rgt-identityN/A
*-lowering-*.f6450.2
Applied egg-rr50.2%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6467.3
Simplified67.3%
sub0-negN/A
neg-lowering-neg.f6467.3
Applied egg-rr67.3%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (- (* (+ z y) x) z))
double code(double x, double y, double z) {
return ((z + y) * 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 = ((z + y) * x) - z
end function
public static double code(double x, double y, double z) {
return ((z + y) * x) - z;
}
def code(x, y, z): return ((z + y) * x) - z
function code(x, y, z) return Float64(Float64(Float64(z + y) * x) - z) end
function tmp = code(x, y, z) tmp = ((z + y) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(z + y\right) \cdot x - z
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+r-N/A
Simplified100.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (- 0.0 z))
double code(double x, double y, double z) {
return 0.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 = 0.0d0 - z
end function
public static double code(double x, double y, double z) {
return 0.0 - z;
}
def code(x, y, z): return 0.0 - z
function code(x, y, z) return Float64(0.0 - z) end
function tmp = code(x, y, z) tmp = 0.0 - z; end
code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}
\\
0 - z
\end{array}
Initial program 97.6%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6434.2
Simplified34.2%
sub0-negN/A
neg-lowering-neg.f6434.2
Applied egg-rr34.2%
Final simplification34.2%
herbie shell --seed 2024196
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))